Crate random_access_storage [] [src]

Abstract interface to implement random-access-storage 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

This example is not tested
extern crate random_access_storage;
use random_access_storage::{Error, Sync, SyncMethods};

struct S;
impl SyncMethods for S {
  fn open(&self) -> Result<(), Error> {
    // ...
  }
  fn write(&self, offset: u64, data: Vec<u8>) -> Result<(), Error> {
    // ...
  }
  fn read(&self, offset: u64, length: u64) -> Result<Vec<u8>, Error> {
    // ...
  }
  fn del(&self, offset: u64, length: u64) -> Result<(), Error> {
    // ...
  }
}

let file = Sync::new(SyncMethods);
file.write(0, b"hello")?;
file.write(0, b" world")?;
let text = file.read(0, 11,)?;
assert!(text, b"hello world");

Re-exports

pub extern crate failure;

Structs

Error

The Error type, which can contain any failure.

Sync

A synchronous implementation of random_access_storage.

Traits

SyncMethods

Methods that need to be implemented for the Sync struct.