Crate random_access_storage [−] [src]
random-access-storage
[][2] [][4] [][6] []8
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
ⓘ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: &[u8]) -> Result<(), Error> { // ... } fn read(&self, offset: u64, length: u64) -> Result<&[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");
Installation
$ cargo add random-access-storage
See Also
License
MIT OR Apache-2.0
Structs
Error |
The |
Sync |
Create a synchronous instance. |
Traits
SyncMethods |
Methods that need to be implemented for the |