pub struct ScopedStorage { /* private fields */ }Expand description
Scoped storage with automatic key prefixing.
Useful for isolating storage between different parts of an application.
Implementations§
Source§impl ScopedStorage
impl ScopedStorage
Sourcepub fn new(storage: Storage, prefix: impl Into<String>) -> Self
pub fn new(storage: Storage, prefix: impl Into<String>) -> Self
Create a new scoped storage with the given prefix.
Sourcepub fn local(prefix: impl Into<String>) -> Self
pub fn local(prefix: impl Into<String>) -> Self
Create a localStorage instance with the given prefix.
Sourcepub fn session(prefix: impl Into<String>) -> Self
pub fn session(prefix: impl Into<String>) -> Self
Create a sessionStorage instance with the given prefix.
Sourcepub fn get_json<T: DeserializeOwned>(
&self,
key: &str,
) -> Result<Option<T>, StorageError>
pub fn get_json<T: DeserializeOwned>( &self, key: &str, ) -> Result<Option<T>, StorageError>
Get a value and deserialize it as JSON.
Sourcepub fn set_json<T: Serialize>(
&self,
key: &str,
value: &T,
) -> Result<(), StorageError>
pub fn set_json<T: Serialize>( &self, key: &str, value: &T, ) -> Result<(), StorageError>
Serialize a value as JSON and store it.
Sourcepub fn clear(&self) -> Result<(), StorageError>
pub fn clear(&self) -> Result<(), StorageError>
Clear all values with this prefix.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for ScopedStorage
impl RefUnwindSafe for ScopedStorage
impl Send for ScopedStorage
impl Sync for ScopedStorage
impl Unpin for ScopedStorage
impl UnsafeUnpin for ScopedStorage
impl UnwindSafe for ScopedStorage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more