random-access-storage

crates.io version build status downloads docs.rs docs

Abstract interface to implement random-access instances.

Why?

This module forms a shared interface for reading and writing bytes to different backends. By having a shared interface, it means implementations can easily be swapped, depending on the environment.

Usage

```rust use randomaccessstorage::{RandomAccessMethods, RandomAccess}; use asynctrait::asynctrait;

struct S;

[async_trait]

impl RandomAccessMethods for S { type Error = std::io::Error;

async fn open(&mut self) -> Result<(), Self::Error> { unimplemented!(); }

async fn write(&mut self, offset: u64, data: &[u8]) -> Result<(), Self::Error> { unimplemented!(); }

async fn read(&mut self, offset: u64, length: u64) -> Result, Self::Error> { unimplemented!(); }

async fn readtowriter( &mut self, offset: u64, length: u64, writer: &mut (impl futures::io::AsyncWriter + Send) ) -> Result<(), Self::Error> { unimplemented!(); }

async fn del(&mut self, offset: u64, length: u64) -> Result<(), Self::Error> { unimplemented!(); }

async fn truncate(&mut self, length: u64) -> Result<(), Self::Error> { unimplemented!(); }

async fn len(&mut self) -> Result { unimplemented!(); }

async fn is_empty(&mut self) -> Result { unimplemented!(); }

async fn sync_all(&mut self) -> Result<(), Self::Error> { unimplemented!(); } }

let _file = RandomAccess::new(S); ```

Installation

sh $ cargo add random-access-storage

See Also

License

MIT OR Apache-2.0