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§
Sourcefn Read(&self, Buffer: &mut [u8]) -> Result_type<Size_type>
fn Read(&self, Buffer: &mut [u8]) -> Result_type<Size_type>
Read data from the device.
Sourcefn Write(&self, Buffer: &[u8]) -> Result_type<Size_type>
fn Write(&self, Buffer: &[u8]) -> Result_type<Size_type>
Write data to the device.
Sourcefn Get_size(&self) -> Result_type<Size_type>
fn Get_size(&self) -> Result_type<Size_type>
Get the size of maximum data that can be read or written.
Sourcefn Set_position(&self, Position: &Position_type) -> Result_type<Size_type>
fn Set_position(&self, Position: &Position_type) -> Result_type<Size_type>
Set the position of the device.
Sourcefn Flush(&self) -> Result_type<()>
fn Flush(&self) -> Result_type<()>
Flush the device (write any buffered data).
Provided Methods§
fn Read_line(&self, Buffer: &mut String) -> Result_type<Size_type>
Sourcefn Erase(&self) -> Result_type<()>
fn Erase(&self) -> Result_type<()>
Erase the device.
This operation is only required for block devices.
Sourcefn Get_block_size(&self) -> Result_type<usize>
fn Get_block_size(&self) -> Result_type<usize>
Get the device block size.