Skip to main content

Crate random_access_storage

Crate random_access_storage 

Source
Expand description

§Abstract interface to implement random-access instances

This crate defines the shared RandomAccess trait that makes it possible to create different backends for reading, writing and deleting bytes. With a shared interface, implementations can easily be swapped, depending on the needs and the environment.

§Known Implementations

Full implementations of RandomAccess include:

§Examples

Your own random-access backend can be implemented like this:

use random_access_storage::{BoxFuture, RandomAccess, RandomAccessError};

struct MyRandomAccess {
    // Add fields here
}

impl RandomAccess for MyRandomAccess {
    fn write(&self, _offset: u64, _data: &[u8]) -> BoxFuture<Result<(), RandomAccessError>> {
        unimplemented!();
    }

    fn read(
        &self,
        _offset: u64,
        _length: u64,
    ) -> BoxFuture<Result<Vec<u8>, RandomAccessError>> {
        unimplemented!();
    }

    fn del(&self, _offset: u64, _length: u64) -> BoxFuture<Result<(), RandomAccessError>> {
        unimplemented!();
    }

    fn truncate(&self, _length: u64) -> BoxFuture<Result<(), RandomAccessError>> {
        unimplemented!();
    }

    fn len(&self) -> u64 {
        unimplemented!();
    }
}

Enums§

RandomAccessError
Error type for the RandomAccess trait methods.

Traits§

RandomAccess
Interface for reading from, writing to and deleting from a randomly accessible storage of bytes.

Type Aliases§

BoxFuture
Convenience alias for the owned, sendable futures returned by RandomAccess::read.