[][src]Trait random_access_storage::RandomAccess

pub trait RandomAccess {
    type Error;
    fn write(&mut self, offset: u64, data: &[u8]) -> Result<(), Self::Error>;
fn read(&mut self, offset: u64, length: u64) -> Result<Vec<u8>, Self::Error>;
fn read_to_writer(
        &mut self,
        offset: u64,
        length: u64,
        buf: &mut impl Write
    ) -> Result<(), Self::Error>;
fn del(&mut self, offset: u64, length: u64) -> Result<(), Self::Error>;
fn truncate(&mut self, length: u64) -> Result<(), Self::Error>;
fn len(&self) -> Result<u64, Self::Error>;
fn is_empty(&mut self) -> Result<bool, Self::Error>;
fn sync_all(&mut self) -> Result<(), Self::Error>; }

The RandomAccess trait allows for reading from and writing to a randomly accessible storage of bytes.

Associated Types

type Error

An error.

Loading content...

Required methods

fn write(&mut self, offset: u64, data: &[u8]) -> Result<(), Self::Error>

Write bytes at an offset to the backend.

fn read(&mut self, offset: u64, length: u64) -> Result<Vec<u8>, Self::Error>

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

fn read_to_writer(
    &mut self,
    offset: u64,
    length: u64,
    buf: &mut impl Write
) -> Result<(), Self::Error>

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

fn del(&mut self, offset: u64, length: u64) -> Result<(), Self::Error>

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

fn truncate(&mut self, length: u64) -> Result<(), Self::Error>

Resize the sequence of bytes, possibly discarding or zero-padding bytes from the end.

fn len(&self) -> Result<u64, Self::Error>

Get the size of the storage in bytes.

fn is_empty(&mut self) -> Result<bool, Self::Error>

Whether the storage is empty. For some storage backends it may be cheaper to calculate whether the storage is empty than to calculate the length.

fn sync_all(&mut self) -> Result<(), Self::Error>

Flush buffered data on the underlying storage resource.

Loading content...

Implementors

Loading content...