storage_device::fake_device

Struct FakeDevice

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

A Device backed by a memory buffer.

Implementations§

Source§

impl FakeDevice

Source

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

Source

pub fn set_op_callback( &mut self, cb: impl Fn(Op) -> Result<(), Error> + Send + Sync + 'static, )

Sets a callback that will run at the beginning of read, write, and flush which will forward any errors, and proceed on Ok().

Source

pub fn from_image(reader: impl Read, block_size: u32) -> Result<Self, Error>

Creates a fake block device from an image (which can be anything that implements std::io::Read). The size of the device is determined by how much data is read.

Trait Implementations§

Source§

impl Device for FakeDevice

Source§

fn poison(&self) -> Result<(), Error>

Sets the poisoned state for the device. A poisoned device will panic the thread that performs Drop on it.

Source§

fn allocate_buffer(&self, size: usize) -> BufferFuture<'_>

Allocates a transfer buffer of at least |size| bytes for doing I/O with the device. The actual size of the buffer will be rounded up to a block-aligned size.
Source§

fn block_size(&self) -> u32

Returns the block size of the device. Buffers are aligned to block-aligned chunks.
Source§

fn block_count(&self) -> u64

Returns the number of blocks of the device.
Source§

fn read<'life0, 'life1, 'async_trait>( &'life0 self, offset: u64, buffer: MutableBufferRef<'life1>, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Fills |buffer| with blocks read from |offset|.
Source§

fn write_with_opts<'life0, 'life1, 'async_trait>( &'life0 self, offset: u64, buffer: BufferRef<'life1>, _opts: WriteOptions, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Writes the contents of |buffer| to the device at |offset|.
Source§

fn trim<'life0, 'async_trait>( &'life0 self, range: Range<u64>, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Trims the given device |range|.
Source§

fn close<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Closes the block device. It is an error to continue using the device after this, but close itself is idempotent.
Source§

fn flush<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Flush the device.
Source§

fn reopen(&self, read_only: bool)

Reopens the device, making it usable again. (Only implemented for testing devices.)
Source§

fn is_read_only(&self) -> bool

Returns whether the device is read-only.
Source§

fn supports_trim(&self) -> bool

Returns whether the device supports trim.
Source§

fn snapshot(&self) -> Result<DeviceHolder, Error>

Returns a snapshot of the device.
Source§

fn discard_random_since_last_flush(&self) -> Result<(), Error>

Discards random blocks since the last flush.
Source§

fn size(&self) -> u64

Returns the size in bytes of the device.
Source§

fn write<'life0, 'life1, 'async_trait>( &'life0 self, offset: u64, buffer: BufferRef<'life1>, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Writes the contents of |buffer| to the device at |offset|.
Source§

impl Drop for FakeDevice

Source§

fn drop(&mut self)

Executes the destructor for this type. 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> 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, D> Encode<Ambiguous1, D> for T
where D: ResourceDialect,

Source§

unsafe fn encode( self, _encoder: &mut Encoder<'_, D>, _offset: usize, _depth: Depth, ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
Source§

impl<T, D> Encode<Ambiguous2, D> for T
where D: ResourceDialect,

Source§

unsafe fn encode( self, _encoder: &mut Encoder<'_, D>, _offset: usize, _depth: Depth, ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V