Struct persisted::SingletonKey
source · pub struct SingletonKey<V> { /* private fields */ }Expand description
A persisted key for a value type that appears only once in a program. The name of the value type is the only information available as the key, hence why the value type must only be used once.
§Example
use persisted::{Persisted, PersistedKey, PersistedStore, SingletonKey};
enum Foo {
Bar,
Baz,
}
#[derive(PersistedKey)]
#[persisted(Foo)]
struct FooKey;
// These two values are equivalent
let value1: Persisted<Store, _> =
Persisted::new(SingletonKey::default(), Foo::Bar);
let value2: Persisted<Store, _> = Persisted::new(FooKey, Foo::Bar);
struct Store;
impl<K: PersistedKey> PersistedStore<K> for Store {
fn load_persisted(key: &K) -> Option<K::Value> {
None
}
fn store_persisted(key: &K, value: &K::Value) {}
}Trait Implementations§
source§impl<V: Clone> Clone for SingletonKey<V>
impl<V: Clone> Clone for SingletonKey<V>
source§fn clone(&self) -> SingletonKey<V>
fn clone(&self) -> SingletonKey<V>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl<V> Debug for SingletonKey<V>
impl<V> Debug for SingletonKey<V>
source§impl<V> Default for SingletonKey<V>
impl<V> Default for SingletonKey<V>
source§impl<V> PersistedKey for SingletonKey<V>
impl<V> PersistedKey for SingletonKey<V>
source§fn type_name() -> &'static str
fn type_name() -> &'static str
Get a unique name for this key type. This should be globally unique
within the scope of your program. This is important to use while
persisting because most serialization formats don’t include the name of
the type, just the content. This unique name allows the store to
disambiguate between different key types of the same structure, which is
particular important for unit keys. For example, if your store persists
data as JSON, a serialized key may be just an ID, e.g.
3. This alone
is not a useful key because it’s ambiguous in the scope of your entire
program. This method allows you to include the key type, so you could
serialize the same key as ["Person", 3] or {"type": "Person", "key": 3}. It’s up to the PersistedStore implementation to decide how to
actually employ this function, it’s provided merely as a utility. Read moreimpl<V: Copy> Copy for SingletonKey<V>
Auto Trait Implementations§
impl<V> Freeze for SingletonKey<V>
impl<V> RefUnwindSafe for SingletonKey<V>where
V: RefUnwindSafe,
impl<V> Send for SingletonKey<V>where
V: Send,
impl<V> Sync for SingletonKey<V>where
V: Sync,
impl<V> Unpin for SingletonKey<V>where
V: Unpin,
impl<V> UnwindSafe for SingletonKey<V>where
V: UnwindSafe,
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit)source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit)