Skip to main content

RandomAccess

Trait RandomAccess 

Source
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§

Source

fn write( &self, offset: u64, data: &[u8], ) -> BoxFuture<Result<(), RandomAccessError>>

Write bytes of data at an offset to the backend.

§Errors
Source

fn read( &self, offset: u64, length: u64, ) -> BoxFuture<Result<Vec<u8>, RandomAccessError>>

Read a sequence of bytes at an offset from the backend.

§Errors
Source

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
Source

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
Source

fn len(&self) -> u64

Get the size of the storage in bytes.

Provided Methods§

Source

fn is_empty(&self) -> bool

Whether the storage is empty.

Source

fn sync_all(&self) -> BoxFuture<Result<(), RandomAccessError>>

Flush buffered data on the underlying storage resource.

§Errors

Implementors§