Struct Device

Source
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

Source

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));
Source

pub fn read(&self, buffer: &mut [u8]) -> Result<Size>

Read data from the device at the current position.

See DeviceTrait::read for detailed documentation.

Source

pub fn write(&self, buffer: &[u8]) -> Result<Size>

Write data to the device at the current position.

See DeviceTrait::write for detailed documentation.

Source

pub fn get_size(&self) -> Result<Size>

Get the total size of the device in bytes.

See DeviceTrait::get_size for detailed documentation.

Source

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.

Source

pub fn flush(&self) -> Result<()>

Flush any buffered data to the underlying storage.

See DeviceTrait::flush for detailed documentation.

Source

pub fn erase(&self) -> Result<()>

Erase the entire device.

See DeviceTrait::erase for detailed documentation.

Source

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.

Source

pub fn is_a_terminal(&self) -> bool

Check if this device represents a terminal/console device.

See DeviceTrait::is_a_terminal for detailed documentation.

Source

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.

Source

pub fn dump_device(&self) -> Result<Vec<u8>>

Create a complete dump of the device contents.

See DeviceTrait::dump_device for detailed documentation.

Trait Implementations§

Source§

impl Clone for Device

Source§

fn clone(&self) -> Device

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Device

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Device

§

impl !RefUnwindSafe for Device

§

impl Send for Device

§

impl Sync for Device

§

impl Unpin for Device

§

impl !UnwindSafe for Device

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.