File_system

Trait Device_trait

Source
pub trait Device_trait: Send + Sync {
    // Required methods
    fn Read(&self, Buffer: &mut [u8]) -> Result_type<Size_type>;
    fn Write(&self, Buffer: &[u8]) -> Result_type<Size_type>;
    fn Get_size(&self) -> Result_type<Size_type>;
    fn Set_position(&self, Position: &Position_type) -> Result_type<Size_type>;
    fn Flush(&self) -> Result_type<()>;

    // Provided methods
    fn Read_line(&self, Buffer: &mut String) -> Result_type<Size_type> { ... }
    fn Erase(&self) -> Result_type<()> { ... }
    fn Get_block_size(&self) -> Result_type<usize> { ... }
    fn Is_a_terminal(&self) -> bool { ... }
    fn Is_a_block_device(&self) -> bool { ... }
    fn Dump_device(&self) -> Result_type<Vec<u8>> { ... }
}
Expand description

A device is a file-like object that can be read from and written to.

This trait is used to abstract the underlying peripheral or file system. A device should be thread-safe, as it may be accessed by multiple tasks/threads concurrently. A device should never block and should return a Error_type::Ressource_busy error if the operation would block. That means that the device should use use std::sync::RwLock::try_read and std::sync::RwLock::try_read.

Required Methods§

Source

fn Read(&self, Buffer: &mut [u8]) -> Result_type<Size_type>

Read data from the device.

Source

fn Write(&self, Buffer: &[u8]) -> Result_type<Size_type>

Write data to the device.

Source

fn Get_size(&self) -> Result_type<Size_type>

Get the size of maximum data that can be read or written.

Source

fn Set_position(&self, Position: &Position_type) -> Result_type<Size_type>

Set the position of the device.

Source

fn Flush(&self) -> Result_type<()>

Flush the device (write any buffered data).

Provided Methods§

Source

fn Read_line(&self, Buffer: &mut String) -> Result_type<Size_type>

Source

fn Erase(&self) -> Result_type<()>

Erase the device.

This operation is only required for block devices.

Source

fn Get_block_size(&self) -> Result_type<usize>

Get the device block size.

Source

fn Is_a_terminal(&self) -> bool

Source

fn Is_a_block_device(&self) -> bool

Source

fn Dump_device(&self) -> Result_type<Vec<u8>>

Implementors§

Source§

impl<const Block_size: usize> Device_trait for Memory_device_type<Block_size>