Abstract interface to implement random-access instances.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
src
.gitignore
.travis.yml
CERTIFICATE
CHANGELOG.md
Cargo.toml
LICENSE-APACHE
LICENSE-MIT
README.md
rustfmt.toml

README.md

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

extern crate random_access_storage;

use random_access_storage::{RandomAccessMethods, RandomAccess};

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

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

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

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

  fn read_to_writer(
    &mut self,
    offset: u64,
    length: u64,
    writer: &mut impl std::io::Writer
  ) -> Result<(), Self::Error> {
    unimplemented!();
  }

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

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

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

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

let _file = RandomAccess::new(S);

Installation

$ cargo add random-access-storage

See Also

License

MIT OR Apache-2.0