pub trait Storage: AsyncTruncate<Mark = Self::Position, TruncError = Self::Error> + AsyncConsume<ConsumeError = Self::Error> + Sizable<Size = Self::Position> {
type Content: Deref<Target = [u8]> + Unpin;
type Position: Unsigned + FromPrimitive + ToPrimitive + Sum + Ord + Copy;
type Error: Error + From<StreamUnexpectedLength>;
// Required methods
fn append_slice<'life0, 'life1, 'async_trait>(
&'life0 mut self,
slice: &'life1 [u8]
) -> Pin<Box<dyn Future<Output = Result<(Self::Position, Self::Size), Self::Error>> + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn read<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
position: &'life1 Self::Position,
size: &'life2 Self::Size
) -> Pin<Box<dyn Future<Output = Result<Self::Content, Self::Error>> + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
// Provided method
fn append<'life0, 'life1, 'async_trait, XBuf, XE, X>(
&'life0 mut self,
buf_stream: &'life1 mut X,
append_threshold: Option<Self::Size>
) -> Pin<Box<dyn Future<Output = Result<(Self::Position, Self::Size), Self::Error>> + 'async_trait>>
where XBuf: Deref<Target = [u8]> + 'async_trait,
X: Stream<Item = Result<XBuf, XE>> + Unpin + 'async_trait,
XE: 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
}
Expand description
Trait representing a read-append-truncate storage media.
Required Associated Types§
sourcetype Content: Deref<Target = [u8]> + Unpin
type Content: Deref<Target = [u8]> + Unpin
Type to represent the content bytes of this storage media.
sourcetype Position: Unsigned + FromPrimitive + ToPrimitive + Sum + Ord + Copy
type Position: Unsigned + FromPrimitive + ToPrimitive + Sum + Ord + Copy
Type to represent data positions inside this storage media.
sourcetype Error: Error + From<StreamUnexpectedLength>
type Error: Error + From<StreamUnexpectedLength>
Error that can occur during storage operations.
Required Methods§
sourcefn append_slice<'life0, 'life1, 'async_trait>(
&'life0 mut self,
slice: &'life1 [u8]
) -> Pin<Box<dyn Future<Output = Result<(Self::Position, Self::Size), Self::Error>> + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn append_slice<'life0, 'life1, 'async_trait>( &'life0 mut self, slice: &'life1 [u8] ) -> Pin<Box<dyn Future<Output = Result<(Self::Position, Self::Size), Self::Error>> + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
Appends the given slice of bytes to the end of this storage.
Implementations must update internal cursor or write pointers, if any, when implementing this method.
sourcefn read<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
position: &'life1 Self::Position,
size: &'life2 Self::Size
) -> Pin<Box<dyn Future<Output = Result<Self::Content, Self::Error>> + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn read<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, position: &'life1 Self::Position, size: &'life2 Self::Size ) -> Pin<Box<dyn Future<Output = Result<Self::Content, Self::Error>> + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,
Reads size
number of bytes from the given position
.
Returns the bytes read.
Provided Methods§
sourcefn append<'life0, 'life1, 'async_trait, XBuf, XE, X>(
&'life0 mut self,
buf_stream: &'life1 mut X,
append_threshold: Option<Self::Size>
) -> Pin<Box<dyn Future<Output = Result<(Self::Position, Self::Size), Self::Error>> + 'async_trait>>where
XBuf: Deref<Target = [u8]> + 'async_trait,
X: Stream<Item = Result<XBuf, XE>> + Unpin + 'async_trait,
XE: 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn append<'life0, 'life1, 'async_trait, XBuf, XE, X>( &'life0 mut self, buf_stream: &'life1 mut X, append_threshold: Option<Self::Size> ) -> Pin<Box<dyn Future<Output = Result<(Self::Position, Self::Size), Self::Error>> + 'async_trait>>where XBuf: Deref<Target = [u8]> + 'async_trait, X: Stream<Item = Result<XBuf, XE>> + Unpin + 'async_trait, XE: 'async_trait, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
Appends a stream of byte slices to the end of this storage.
This method writes at max append_threshold
number of bytes from the
given stream of bytes slices. If the provided append_threshold
is
None
, no such check is enforced; we attempt to write the entire
stream until it’s exhausted.
The following error scenarios may occur during writing:
append_threshold
isSome(_)
, and the stream contains more bytes than the threshold- The stream unexpectedly yields an error when attempting to read the next byte slice from the stream
- There is a storage error when attempting to write one of the byte slices from the stream.
In all of the above error cases, we truncate this storage media with the size of the storage media before we started the append operation, effectively rolling back any writes.
Returns the position where the bytes were written and the number of bytes written.