Skip to main content

Storage

Trait Storage 

Source
pub trait Storage: Debug {
    // Required methods
    fn read(&self, key: &str) -> Result<Option<String>, StorageError>;
    fn write(&mut self, key: &str, value: &str) -> Result<(), StorageError>;
    fn delete(&mut self, key: &str) -> Result<(), StorageError>;
    fn list(&self) -> Result<Vec<String>, StorageError>;
}
Expand description

A place to persist small named blobs of text (RON documents, typically): files on native, localStorage on web.

Keys must match ^[a-z0-9_-]{1,64}$ (is_valid_key); implementations turn a key straight into a file name, so anything else is rejected rather than sanitised.

Required Methods§

Source

fn read(&self, key: &str) -> Result<Option<String>, StorageError>

The value stored at key, or None if nothing has been written there (or it was deleted).

Source

fn write(&mut self, key: &str, value: &str) -> Result<(), StorageError>

Stores value at key, replacing whatever was there.

Source

fn delete(&mut self, key: &str) -> Result<(), StorageError>

Removes key. Not an error if it didn’t exist.

Source

fn list(&self) -> Result<Vec<String>, StorageError>

Every key currently stored, in no particular order.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§