Skip to main content

Storage

Trait Storage 

Source
pub trait Storage {
    // Required method
    fn raw() -> Storage;

    // Provided methods
    fn get<T>(key: impl AsRef<str>) -> Result<T>
       where T: for<'de> Deserialize<'de> { ... }
    fn get_all<T>() -> Result<T>
       where T: for<'a> Deserialize<'a> { ... }
    fn set<T>(key: impl AsRef<str>, value: T) -> Result<()>
       where T: Serialize { ... }
    fn delete(key: impl AsRef<str>) { ... }
    fn clear() { ... }
    fn length() -> u32 { ... }
}
Expand description

Trait which provides implementations for managing storage in the browser.

Required Methods§

Source

fn raw() -> Storage

Get the raw web_sys::Storage instance

Provided Methods§

Source

fn get<T>(key: impl AsRef<str>) -> Result<T>
where T: for<'de> Deserialize<'de>,

Get the value for the specified key

Source

fn get_all<T>() -> Result<T>
where T: for<'a> Deserialize<'a>,

Get all the stored keys and their values

Source

fn set<T>(key: impl AsRef<str>, value: T) -> Result<()>
where T: Serialize,

Insert a value for the specified key

Source

fn delete(key: impl AsRef<str>)

Remove a key and it’s stored value

Source

fn clear()

Remove all the stored data

Source

fn length() -> u32

Get the number of items stored

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§