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:
- 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::{RandomAccess, RandomAccessError};
use async_trait::async_trait;
struct MyRandomAccess {
// Add fields here
}
#[async_trait]
impl RandomAccess for MyRandomAccess {
async fn write(&mut self, _offset: u64, _data: &[u8]) -> Result<(), RandomAccessError> {
unimplemented!();
}
async fn read(&mut self, _offset: u64, _length: u64) -> Result<Vec<u8>, RandomAccessError> {
unimplemented!();
}
async fn del(&mut self, _offset: u64, _length: u64) -> Result<(), RandomAccessError> {
unimplemented!();
}
async fn truncate(&mut self, _length: u64) -> Result<(), RandomAccessError> {
unimplemented!();
}
async fn len(&mut self) -> Result<u64, RandomAccessError> {
unimplemented!();
}
async fn is_empty(&mut self) -> Result<bool, RandomAccessError> {
unimplemented!();
}
async fn sync_all(&mut self) -> Result<(), RandomAccessError> {
unimplemented!();
}
}
Enums
- Error type for the RandomAccess trait methods.
Traits
- Interface for reading from, writing to and deleting from a randomly accessible storage of bytes.