pub struct Device(/* private fields */);
Expand description
Thread-safe wrapper for device implementations.
DeviceType
provides a unified interface for all device implementations by wrapping
them in an Arc<dyn DeviceTrait>
. This allows for efficient cloning and sharing of
device references across threads while maintaining type erasure.
§Examples
// Create a device using the convenience macro
let device1 = create_device!(Memory_device_type::<512>::new(1024));
// Create a device manually
let memory_device = Memory_device_type::<512>::new(1024);
let device2 = DeviceType::new(Arc::new(memory_device));
// Clone the device (cheap operation - only clones the Arc)
let device_clone = device1.clone();
Implementations§
Source§impl Device
impl Device
Sourcepub fn new(device: Arc<dyn DeviceTrait>) -> Self
pub fn new(device: Arc<dyn DeviceTrait>) -> Self
Create a new device wrapper from any implementation of DeviceTrait
.
§Arguments
Device
- Arc containing the device implementation
§Examples
let memory_device = Memory_device_type::<512>::new(1024);
let device = DeviceType::new(Arc::new(memory_device));
Sourcepub fn read(&self, buffer: &mut [u8]) -> Result<Size>
pub fn read(&self, buffer: &mut [u8]) -> Result<Size>
Read data from the device at the current position.
See DeviceTrait::read
for detailed documentation.
Sourcepub fn write(&self, buffer: &[u8]) -> Result<Size>
pub fn write(&self, buffer: &[u8]) -> Result<Size>
Write data to the device at the current position.
See DeviceTrait::write
for detailed documentation.
Sourcepub fn get_size(&self) -> Result<Size>
pub fn get_size(&self) -> Result<Size>
Get the total size of the device in bytes.
See DeviceTrait::get_size
for detailed documentation.
Sourcepub fn set_position(&self, position: &Position) -> Result<Size>
pub fn set_position(&self, position: &Position) -> Result<Size>
Set the current position cursor for read/write operations.
See DeviceTrait::set_position
for detailed documentation.
Sourcepub fn flush(&self) -> Result<()>
pub fn flush(&self) -> Result<()>
Flush any buffered data to the underlying storage.
See DeviceTrait::flush
for detailed documentation.
Sourcepub fn erase(&self) -> Result<()>
pub fn erase(&self) -> Result<()>
Erase the entire device.
See DeviceTrait::erase
for detailed documentation.
Sourcepub fn get_block_size(&self) -> Result<usize>
pub fn get_block_size(&self) -> Result<usize>
Get the block size of the device in bytes.
See DeviceTrait::get_block_size
for detailed documentation.
Sourcepub fn is_a_terminal(&self) -> bool
pub fn is_a_terminal(&self) -> bool
Check if this device represents a terminal/console device.
See DeviceTrait::is_a_terminal
for detailed documentation.
Sourcepub fn is_a_block_device(&self) -> bool
pub fn is_a_block_device(&self) -> bool
Check if this device is a block device.
See DeviceTrait::is_a_block_device
for detailed documentation.
Sourcepub fn dump_device(&self) -> Result<Vec<u8>>
pub fn dump_device(&self) -> Result<Vec<u8>>
Create a complete dump of the device contents.
See DeviceTrait::dump_device
for detailed documentation.