virtio_drivers::device::console

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> BufRead for VirtIOConsole<H, T>

Source§

fn fill_buf(&mut self) -> Result<&[u8], Self::Error>

Return the contents of the internal buffer, filling it with more data from the inner reader if it is empty. Read more
Source§

fn consume(&mut self, amt: usize)

Tell this buffer that amt bytes have been consumed from the buffer, so they should no longer be returned in calls to fill_buf.
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> ErrorType for VirtIOConsole<H, T>

Source§

type Error = Error

Error type of all the IO operations on this type.
Source§

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

Source§

fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>

Read some bytes from this source into the specified buffer, returning how many bytes were read. Read more
Source§

fn read_exact( &mut self, buf: &mut [u8], ) -> Result<(), ReadExactError<Self::Error>>

Read the exact number of bytes required to fill buf. Read more
Source§

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

Source§

fn read_ready(&mut self) -> Result<bool, Self::Error>

Get whether the reader is ready for immediately reading. Read more
Source§

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

Source§

fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error>

Write a buffer into this writer, returning how many bytes were written. Read more
Source§

fn flush(&mut self) -> Result<(), Self::Error>

Flush this output stream, blocking until all intermediately buffered contents reach their destination.
Source§

fn write_all(&mut self, buf: &[u8]) -> Result<(), Self::Error>

Write an entire buffer into this writer. Read more
Source§

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

Write a formatted string into this writer, returning any error encountered. 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 · Source§

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 · Source§

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>

§

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§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.