Trait CharDevice

Source
pub trait CharDevice: Device {
    // Required methods
    fn read_byte(&mut self) -> Option<u8>;
    fn write_byte(&mut self, byte: u8) -> Result<(), &'static str>;
    fn can_read(&self) -> bool;
    fn can_write(&self) -> bool;

    // Provided methods
    fn read(&mut self, buffer: &mut [u8]) -> usize { ... }
    fn write(&mut self, buffer: &[u8]) -> Result<usize, &'static str> { ... }
}
Expand description

Character device interface

This trait defines the interface for character devices. It provides methods for querying device information and handling character I/O operations.

Required Methods§

Source

fn read_byte(&mut self) -> Option<u8>

Read a single byte from the device

§Returns

The byte read from the device, or None if no data is available

Source

fn write_byte(&mut self, byte: u8) -> Result<(), &'static str>

Write a single byte to the device

§Arguments
  • byte - The byte to write to the device
§Returns

Result indicating success or failure

Source

fn can_read(&self) -> bool

Check if the device is ready for reading

Source

fn can_write(&self) -> bool

Check if the device is ready for writing

Provided Methods§

Source

fn read(&mut self, buffer: &mut [u8]) -> usize

Read multiple bytes from the device

§Arguments
  • buffer - The buffer to read data into
§Returns

The number of bytes actually read

Source

fn write(&mut self, buffer: &[u8]) -> Result<usize, &'static str>

Write multiple bytes to the device

§Arguments
  • buffer - The buffer containing data to write
§Returns

Result containing the number of bytes written or an error

Implementors§