pub trait Backend: ReceiveHeader<Self>where
Self: Sized,{
type Settings: Binary + Clone;
type Err: Error + Send + Sync;
type Id: Binary + Clone + Display + FromStr + IdSize + PartialEq;
type Info;
// Required methods
fn info(&self) -> Result<Self::Info, Self::Err>;
fn block_size(&self) -> u32;
fn aquire(&mut self, buf: &[u8]) -> Result<Self::Id, Self::Err>;
fn release(&mut self, id: Self::Id) -> Result<(), Self::Err>;
fn read(
&mut self,
id: &Self::Id,
buf: &mut [u8],
) -> Result<usize, Self::Err>;
fn write(&mut self, id: &Self::Id, buf: &[u8]) -> Result<usize, Self::Err>;
fn write_header(&mut self, buf: &[u8; 512]) -> Result<(), Self::Err>;
fn delete(self);
}
Expand description
Trait that describes a backend of a container.
Required Associated Types§
Sourcetype Id: Binary + Clone + Display + FromStr + IdSize + PartialEq
type Id: Binary + Clone + Display + FromStr + IdSize + PartialEq
The id identifies a block in the storage. It is used everywhere you need a pointer to a block.
Sourcetype Info
type Info
Information of the backend.
It includes information like public settings. The difference to
Backend::Settings
is that Backend::Settings
might include
sensible information which are removed from Backend::Info
.
Required Methods§
Sourcefn info(&self) -> Result<Self::Info, Self::Err>
fn info(&self) -> Result<Self::Info, Self::Err>
Returns information from the backend.
It includes information like public settings. The difference to
Backend::Settings
is that Backend::Settings
might include
sensible information which are removed from Backend::Info
.
§Errors
On any error a self-defined Backend::Err
is returned.
Sourcefn block_size(&self) -> u32
fn block_size(&self) -> u32
Returns the block size of the backend.
Sourcefn aquire(&mut self, buf: &[u8]) -> Result<Self::Id, Self::Err>
fn aquire(&mut self, buf: &[u8]) -> Result<Self::Id, Self::Err>
Aquires a new block in the backend.
Once aquired you should be able to read and write from/to it.
buf
contains the initial data, which should be copied into the block.
- A
buf
which is not large enough to fill the whole block must be rejected and an error must be returned. - If
buf
holds more data than the block-size, then only the first block-size bytes are copied into the block.
By default an aquired block, which is not written yet, should return an all-zero buffer.
Returns the id if the block.
§Errors
On any error a self-defined Backend::Err
is returned.
Sourcefn release(&mut self, id: Self::Id) -> Result<(), Self::Err>
fn release(&mut self, id: Self::Id) -> Result<(), Self::Err>
Releases a block again.
A released block cannot be read and written, the id cannot be used afterwards.
§Errors
On any error a self-defined Backend::Err
is returned.
Sourcefn read(&mut self, id: &Self::Id, buf: &mut [u8]) -> Result<usize, Self::Err>
fn read(&mut self, id: &Self::Id, buf: &mut [u8]) -> Result<usize, Self::Err>
Reads a block from the backend.
Reads the block with the given id
and places the data in buf
.
You cannot read not more data than the
block-size bytes. If buf
is larger, than not
the whole buffer is filled. In the other direction, if buf
is not
large enough to store the whole block, buf
is filled with the first
buf.len()
bytes.
The methods returns the number of bytes actually read, which cannot be greater than the block-size.
§Errors
On any error a self-defined Backend::Err
is returned.
Sourcefn write(&mut self, id: &Self::Id, buf: &[u8]) -> Result<usize, Self::Err>
fn write(&mut self, id: &Self::Id, buf: &[u8]) -> Result<usize, Self::Err>
Writes a block into the backend.
Writes up to buf.len()
bytes from the unencrypted buf
buffer into
the block with the given id
.
- A
buf
which is not large enough to fill the whole block must be rejected and an error must be returned. - If
buf
holds more data than the block-size, then only the first block-size bytes are copied into the block.
The method returns the number of bytes actually written.
§Errors
On any error a self-defined Backend::Err
is returned.
Sourcefn write_header(&mut self, buf: &[u8; 512]) -> Result<(), Self::Err>
fn write_header(&mut self, buf: &[u8; 512]) -> Result<(), Self::Err>
Puts the given buf
into the header of the backend.
The container uses this method to ask the backend to put data into the
header. The container does not know where the backend stores the
header, that’s why such a method is used. Not more than
HEADER_MAX_SIZE
bytes can be stored in the header.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.