VirtIOConsole

Struct VirtIOConsole 

Source
pub struct VirtIOConsole<H: Hal, T: Transport> { /* private fields */ }
Expand description

Driver for a VirtIO console device.

Only a single port is supported.

§Example

use virtio_drivers::device::console::VirtIOConsole;
let mut console = VirtIOConsole::<HalImpl, _>::new(transport)?;

let size = console.size().unwrap().unwrap();
println!("VirtIO console {}x{}", size.rows, size.columns);

for &c in b"Hello console!\n" {
  console.send(c)?;
}

let c = console.recv(true)?;
println!("Read {:?} from console.", c);

Implementations§

Source§

impl<H: Hal, T: Transport> VirtIOConsole<H, T>

Source

pub fn new(transport: T) -> Result<Self>

Creates a new VirtIO console driver.

Source

pub fn size(&self) -> Result<Option<Size>>

Returns the size of the console, if the device supports reporting this.

Source

pub fn ack_interrupt(&mut self) -> Result<bool>

Acknowledges a pending interrupt, if any, and completes the outstanding finished read request if there is one.

Returns true if new data has been received.

Source

pub fn recv(&mut self, pop: bool) -> Result<Option<u8>>

Returns the next available character from the console, if any.

If no data has been received this will not block but immediately return Ok<None>.

Source

pub fn send(&mut self, chr: u8) -> Result<()>

Sends a character to the console.

Source

pub fn send_bytes(&mut self, buffer: &[u8]) -> Result

Sends one or more bytes to the console.

Source

pub fn emergency_write(&mut self, chr: u8) -> Result<()>

Sends a character to the console using the emergency write feature.

Returns an error if the device doesn’t support emergency write.

Trait Implementations§

Source§

impl<H: Hal, T: Transport> Drop for VirtIOConsole<H, T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<H: Hal, T: Transport> Write for VirtIOConsole<H, T>

Source§

fn write_str(&mut self, s: &str) -> Result

Writes a string slice into this writer, returning whether the write succeeded. Read more
1.1.0§

fn write_char(&mut self, c: char) -> Result<(), Error>

Writes a [char] into this writer, returning whether the write succeeded. Read more
1.0.0§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Glue for usage of the [write!] macro with implementors of this trait. Read more
Source§

impl<H: Hal, T: Transport + Send> Send for VirtIOConsole<H, T>
where VirtQueue<H, QUEUE_SIZE>: Send,

Source§

impl<H: Hal, T: Transport + Sync> Sync for VirtIOConsole<H, T>
where VirtQueue<H, QUEUE_SIZE>: Sync,

Auto Trait Implementations§

§

impl<H, T> Freeze for VirtIOConsole<H, T>
where T: Freeze,

§

impl<H, T> RefUnwindSafe for VirtIOConsole<H, T>
where T: RefUnwindSafe, H: RefUnwindSafe,

§

impl<H, T> Unpin for VirtIOConsole<H, T>
where T: Unpin, H: Unpin,

§

impl<H, T> UnwindSafe for VirtIOConsole<H, T>
where T: UnwindSafe, H: UnwindSafe,

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.