Struct block_cache::BlockCache
source · pub struct BlockCache { /* private fields */ }
Expand description
A cache to store read and written blocks from a storage device.
Implementations§
source§impl BlockCache
impl BlockCache
sourcepub fn new(storage_device: StorageDeviceRef) -> BlockCache
pub fn new(storage_device: StorageDeviceRef) -> BlockCache
Creates a new BlockCache
device
sourcepub fn flush(&mut self, block_num: Option<usize>) -> Result<(), &'static str>
pub fn flush(&mut self, block_num: Option<usize>) -> Result<(), &'static str>
Flushes the given block to the backing storage device.
If the block_to_flush
is None, all blocks in the entire cache
will be written back to the storage device.
sourcepub fn read_block(
cache: &mut BlockCache,
block: usize
) -> Result<&[u8], &'static str>
pub fn read_block( cache: &mut BlockCache, block: usize ) -> Result<&[u8], &'static str>
An internal function that first checks the cache for a specific block in order to avoid reading from the storage device. If that block exists in the cache, it is copied into the buffer. If not, it is read from the storage device into the cache, and then copied into the buffer.
pub fn write_block( &mut self, block_num: usize, buffer_to_write: Cow<'_, [u8]> ) -> Result<(), &'static str>
Auto Trait Implementations§
impl !RefUnwindSafe for BlockCache
impl Send for BlockCache
impl Sync for BlockCache
impl Unpin for BlockCache
impl !UnwindSafe for BlockCache
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere T: Any,
§fn into_any(self: Box<T, Global>) -> Box<dyn Any, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any, Global>
Convert
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T, Global>) -> Rc<dyn Any, Global>
fn into_any_rc(self: Rc<T, Global>) -> Rc<dyn Any, Global>
Convert
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.