Skip to main content

MemoryBlockDevice

Struct MemoryBlockDevice 

Source
pub struct MemoryBlockDevice { /* private fields */ }
Expand description

A block device backed by memory.

This is useful for testing and embedded scenarios where no persistent storage is available.

Implementations§

Source§

impl MemoryBlockDevice

Source

pub fn new(size: u64, block_size: u32) -> Self

Create a new in-memory block device.

§Arguments
  • size - Total size in bytes
  • block_size - Block size in bytes (typically 512 or 4096)
§Returns

A new MemoryBlockDevice

Source

pub fn with_size(size: u64) -> Self

Create a new in-memory block device with default block size (512 bytes).

Source

pub fn from_vec(data: Vec<u8>, block_size: u32) -> Self

Create a block device from existing data.

§Arguments
  • data - The data to wrap
  • block_size - Block size in bytes
§Panics

Panics if data length is not aligned to block_size

Source

pub fn as_slice(&self) -> &[u8]

Get the underlying data as a slice.

Source

pub fn as_mut_slice(&mut self) -> &mut [u8]

Get the underlying data as a mutable slice.

Source

pub fn into_vec(self) -> Vec<u8>

Consume the device and return the underlying data.

Trait Implementations§

Source§

impl BlockDevice for MemoryBlockDevice

Source§

fn read_blocks(&self, block_id: u64, buf: &mut [u8]) -> Result<u32>

Read blocks from the device. Read more
Source§

fn write_blocks(&mut self, block_id: u64, buf: &[u8]) -> Result<u32>

Write blocks to the device. Read more
Source§

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

Flush any pending writes to the device.
Source§

fn block_size(&self) -> u32

Get the physical block size in bytes.
Source§

fn block_count(&self) -> u64

Get the total number of blocks.
Source§

fn open(&mut self) -> Result<()>

Open the device (called before first I/O operation). Read more
Source§

fn close(&mut self) -> Result<()>

Close the device (called when unmounting). Read more

Auto Trait Implementations§

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> BlockDeviceExt for T
where T: BlockDevice,

Source§

fn total_size(&self) -> u64

Get the total size of the device in bytes.
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> 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, 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.