pub trait RandomAccess {
// Required methods
fn write(
&self,
offset: u64,
data: &[u8],
) -> BoxFuture<Result<(), RandomAccessError>>;
fn read(
&self,
offset: u64,
length: u64,
) -> BoxFuture<Result<Vec<u8>, RandomAccessError>>;
fn del(
&self,
offset: u64,
length: u64,
) -> BoxFuture<Result<(), RandomAccessError>>;
fn truncate(&self, length: u64) -> BoxFuture<Result<(), RandomAccessError>>;
fn len(&self) -> u64;
// Provided methods
fn is_empty(&self) -> bool { ... }
fn sync_all(&self) -> BoxFuture<Result<(), RandomAccessError>> { ... }
}Expand description
Interface for reading from, writing to and deleting from a randomly accessible storage of bytes.
Required Methods§
Sourcefn write(
&self,
offset: u64,
data: &[u8],
) -> BoxFuture<Result<(), RandomAccessError>>
fn write( &self, offset: u64, data: &[u8], ) -> BoxFuture<Result<(), RandomAccessError>>
Write bytes of data at an offset to the backend.
§Errors
-
RandomAccessError::OutOfBounds if the backend has a maximum capacity that would be exceeded by the write.
-
RandomAccessError::IO if an unexpected IO error occurred.
Sourcefn read(
&self,
offset: u64,
length: u64,
) -> BoxFuture<Result<Vec<u8>, RandomAccessError>>
fn read( &self, offset: u64, length: u64, ) -> BoxFuture<Result<Vec<u8>, RandomAccessError>>
Read a sequence of bytes at an offset from the backend.
§Errors
-
RandomAccessError::OutOfBounds if RandomAccess::len >
offset+length. -
RandomAccessError::IO if an unexpected IO error occurred.
Sourcefn del(
&self,
offset: u64,
length: u64,
) -> BoxFuture<Result<(), RandomAccessError>>
fn del( &self, offset: u64, length: u64, ) -> BoxFuture<Result<(), RandomAccessError>>
Delete a sequence of bytes of given length at an offset from the backend.
This either sets the bytes in the given slice to zeroes, or if
offset + length >= RandomAccess::len() is the same as
truncate(offset).
§Errors
-
RandomAccessError::OutOfBounds if RandomAccess::len() <
offset+length. -
RandomAccessError::IO if an unexpected IO error occurred.
Sourcefn truncate(&self, length: u64) -> BoxFuture<Result<(), RandomAccessError>>
fn truncate(&self, length: u64) -> BoxFuture<Result<(), RandomAccessError>>
Resize the sequence of bytes so that RandomAccess::len() is set to
length. If length < RandomAccess::len(), the bytes are disregarded.
If length > RandomAccess::len(), the storage is zero-padded.
§Errors
-
RandomAccessError::OutOfBounds if the backend has a maximum capacity smaller than
length. -
RandomAccessError::IO if an unexpected IO error occurred.
Provided Methods§
Sourcefn sync_all(&self) -> BoxFuture<Result<(), RandomAccessError>>
fn sync_all(&self) -> BoxFuture<Result<(), RandomAccessError>>
Flush buffered data on the underlying storage resource.
§Errors
- RandomAccessError::IO if an unexpected IO error occurred.