Skip to main content

Storage

Trait Storage 

Source
pub trait Storage {
    // Required methods
    fn read(&self, name: &str) -> Result<Option<Vec<u8>>, String>;
    fn write(&self, name: &str, bytes: &[u8]) -> Result<(), String>;
    fn remove(&self, name: &str) -> Result<(), String>;
}
Expand description

Named pieces of data kept between runs.

use ravenrs_core::{MemoryStorage, Storage};

let storage = MemoryStorage::default();
storage.write("records", b"{}")?;
assert_eq!(storage.read("records")?, Some(b"{}".to_vec()));
storage.remove("records")?;
assert_eq!(storage.read("records")?, None);

Required Methods§

Source

fn read(&self, name: &str) -> Result<Option<Vec<u8>>, String>

What is kept under name, or None if nothing is.

Source

fn write(&self, name: &str, bytes: &[u8]) -> Result<(), String>

Keeps bytes under name, in place of what was there.

Source

fn remove(&self, name: &str) -> Result<(), String>

Forgets what is kept under name.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<S: Storage + ?Sized> Storage for Rc<S>

Source§

fn read(&self, name: &str) -> Result<Option<Vec<u8>>, String>

Source§

fn write(&self, name: &str, bytes: &[u8]) -> Result<(), String>

Source§

fn remove(&self, name: &str) -> Result<(), String>

Implementors§

Source§

impl Storage for FileStorage

Available on non-WebAssembly only.
Source§

impl Storage for MemoryStorage