pub struct MemoryBackend { /* private fields */ }
Implementations§
Source§impl MemoryBackend
impl MemoryBackend
Sourcepub fn new() -> MemoryBackend
pub fn new() -> MemoryBackend
Creates a new instance of the MemoryBackend
type.
The block-size is set to 512 bytes.
Sourcepub fn new_with_bsize(bsize: u32) -> MemoryBackend
pub fn new_with_bsize(bsize: u32) -> MemoryBackend
Creates a new instance of the MemoryBackend
type with the given
block-size.
Sourcepub fn block_size(&self) -> u32
pub fn block_size(&self) -> u32
Returns the block size specified for this backend instance.
Sourcepub fn get(&self, id: &Id) -> Option<&[u8]>
pub fn get(&self, id: &Id) -> Option<&[u8]>
Receives the content of the block with the given id
.
Returns None
if the block does not exist.
Sourcepub fn insert(&mut self) -> Result<Id, Error>
pub fn insert(&mut self) -> Result<Id, Error>
Inserts a new block.
The block contains only zeros.
Returns the id of the new block.
Sourcepub fn insert_data(&mut self, data: &[u8]) -> Result<Id, Error>
pub fn insert_data(&mut self, data: &[u8]) -> Result<Id, Error>
Inserts a new block with some initial data.
Assigns the first block-size
bytes from data
to
the new block. If data
does not have block-size
bytes, the new block is padded with zero bytes.
Returns the id of the new block.
Trait Implementations§
Source§impl Backend for MemoryBackend
impl Backend for MemoryBackend
Source§type Id = Id
type Id = Id
The id identifies a block in the storage. It is used everywhere you
need a pointer to a block.
Source§fn block_size(&self) -> u32
fn block_size(&self) -> u32
Returns the block size of the backend.
Source§fn aquire(&mut self, buf: &[u8]) -> Result<Id, Error>
fn aquire(&mut self, buf: &[u8]) -> Result<Id, Error>
Aquires a new block in the backend. Read more
Source§fn read(&mut self, id: &Id, buf: &mut [u8]) -> Result<usize, Error>
fn read(&mut self, id: &Id, buf: &mut [u8]) -> Result<usize, Error>
Reads a block from the backend. Read more
Source§fn write(&mut self, id: &Id, buf: &[u8]) -> Result<usize, Error>
fn write(&mut self, id: &Id, buf: &[u8]) -> Result<usize, Error>
Writes a block into the backend. Read more
Source§impl Create<MemoryBackend> for MemoryBackend
impl Create<MemoryBackend> for MemoryBackend
Source§impl Debug for MemoryBackend
impl Debug for MemoryBackend
Source§impl Default for MemoryBackend
impl Default for MemoryBackend
Source§impl<'de> Deserialize<'de> for MemoryBackend
impl<'de> Deserialize<'de> for MemoryBackend
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Open<MemoryBackend> for MemoryBackend
impl Open<MemoryBackend> for MemoryBackend
Source§impl PartialEq for MemoryBackend
impl PartialEq for MemoryBackend
Source§impl ReceiveHeader<MemoryBackend> for MemoryBackend
impl ReceiveHeader<MemoryBackend> for MemoryBackend
Source§impl Serialize for MemoryBackend
impl Serialize for MemoryBackend
impl StructuralPartialEq for MemoryBackend
Auto Trait Implementations§
impl Freeze for MemoryBackend
impl RefUnwindSafe for MemoryBackend
impl Send for MemoryBackend
impl Sync for MemoryBackend
impl Unpin for MemoryBackend
impl UnwindSafe for MemoryBackend
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