#random-access #interface #instance #abstract #storage #traits #back-end

random-access-storage

Abstract interface to implement random-access instances

12 releases (5 stable)

5.0.0 Apr 12, 2023
4.0.0 Mar 3, 2020
3.0.0 Jul 27, 2019
2.0.0 Dec 18, 2018
0.3.0 Mar 21, 2018

#815 in Asynchronous

Download history 455/week @ 2024-06-16 226/week @ 2024-06-23 222/week @ 2024-06-30 294/week @ 2024-07-07 438/week @ 2024-07-14 81/week @ 2024-07-21 87/week @ 2024-07-28 52/week @ 2024-08-04 46/week @ 2024-08-11 37/week @ 2024-08-18 48/week @ 2024-08-25 128/week @ 2024-09-01 195/week @ 2024-09-08 22/week @ 2024-09-15 159/week @ 2024-09-22 87/week @ 2024-09-29

498 downloads per month
Used in 10 crates (6 directly)

MIT/Apache

14KB
57 lines

random-access-storage

crates.io version build status downloads docs.rs docs

Abstract interface to implement random-access instances.

Installation

$ cargo add random-access-storage

See Also

License

MIT OR Apache-2.0


lib.rs:

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::{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!();
  }
}

Dependencies

~260–720KB
~17K SLoC