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:
- random-access-memory for in-memory storage
- random-access-disk for disk storage
§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§
- Random
Access Error - Error type for the RandomAccess trait methods.
Traits§
- Random
Access - 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.