pub struct StoreState(/* private fields */);Expand description
Internal state of a store.
Implementations§
Source§impl StoreState
impl StoreState
Sourcepub fn new() -> StoreState
pub fn new() -> StoreState
Creates an empty StoreState.
Sourcepub fn with_capacity(capacity: usize) -> StoreState
pub fn with_capacity(capacity: usize) -> StoreState
Creates an empty StoreState with at least the specified capacity.
Sourcepub fn into_inner(self) -> HashMap<String, Value>
pub fn into_inner(self) -> HashMap<String, Value>
Consumes the StoreState and returns the inner HashMap.
Sourcepub fn get_raw(&self, key: impl AsRef<str>) -> Option<&Value>
pub fn get_raw(&self, key: impl AsRef<str>) -> Option<&Value>
Gets a reference to the raw value corresponding to the key.
Sourcepub fn get_raw_mut(&mut self, key: impl AsRef<str>) -> Option<&mut Value>
pub fn get_raw_mut(&mut self, key: impl AsRef<str>) -> Option<&mut Value>
Gets a mutable reference to the raw value corresponding to the key.
Sourcepub unsafe fn get_raw_unchecked(&self, key: impl AsRef<str>) -> &Value
pub unsafe fn get_raw_unchecked(&self, key: impl AsRef<str>) -> &Value
Gets a reference to the raw value corresponding to the key.
§Safety
This is undefined behavior if the key doesn’t exist in the store.
Sourcepub unsafe fn get_raw_unchecked_mut(
&mut self,
key: impl AsRef<str>,
) -> &mut Value
pub unsafe fn get_raw_unchecked_mut( &mut self, key: impl AsRef<str>, ) -> &mut Value
Gets a mutable reference to the raw value corresponding to the key.
§Safety
This is undefined behavior if the key doesn’t exist in the store.
Sourcepub fn get<T>(&self, key: impl AsRef<str>) -> Result<T, Error>where
T: DeserializeOwned,
pub fn get<T>(&self, key: impl AsRef<str>) -> Result<T, Error>where
T: DeserializeOwned,
Gets a value and tries to parse it as an instance of type T.
Sourcepub fn get_or<T>(&self, key: impl AsRef<str>, default: T) -> Twhere
T: DeserializeOwned,
pub fn get_or<T>(&self, key: impl AsRef<str>, default: T) -> Twhere
T: DeserializeOwned,
Gets a value and tries to parse it as an instance of type T.
If it does not exist, returns the provided default value.
Sourcepub fn get_or_default<T>(&self, key: impl AsRef<str>) -> Twhere
T: DeserializeOwned + Default,
pub fn get_or_default<T>(&self, key: impl AsRef<str>) -> Twhere
T: DeserializeOwned + Default,
Gets a value and tries to parse it as an instance of type T.
If it does not exist, returns the default value of T.
Sourcepub fn get_or_else<T>(&self, key: impl AsRef<str>, f: impl FnOnce() -> T) -> Twhere
T: DeserializeOwned,
pub fn get_or_else<T>(&self, key: impl AsRef<str>, f: impl FnOnce() -> T) -> Twhere
T: DeserializeOwned,
Gets a value and tries to parse it as an instance of type T.
If it does not exist, returns the result of the provided closure.
Sourcepub unsafe fn get_unchecked<T>(&self, key: impl AsRef<str>) -> Twhere
T: DeserializeOwned,
pub unsafe fn get_unchecked<T>(&self, key: impl AsRef<str>) -> Twhere
T: DeserializeOwned,
Gets a value and parses it as an instance of type T.
§Safety
This is undefined behavior if the key doesn’t exist in the store
OR if the value cannot be represented as a valid T.
Sourcepub fn set(
&mut self,
key: impl AsRef<str>,
value: impl Into<Value>,
) -> Option<Value>
pub fn set( &mut self, key: impl AsRef<str>, value: impl Into<Value>, ) -> Option<Value>
Sets a key-value pair, returning the previous value, if any.
Sourcepub fn patch(&mut self, state: impl Into<StoreState>)
pub fn patch(&mut self, state: impl Into<StoreState>)
Patches the state.
Sourcepub fn values_mut(&mut self) -> impl Iterator<Item = &mut Value>
pub fn values_mut(&mut self) -> impl Iterator<Item = &mut Value>
Creates an iterator over mutable references to the values.
Sourcepub fn entries(&self) -> impl Iterator<Item = (&String, &Value)>
pub fn entries(&self) -> impl Iterator<Item = (&String, &Value)>
Creates an iterator over the entries.
Sourcepub fn entries_mut(&mut self) -> impl Iterator<Item = (&String, &mut Value)>
pub fn entries_mut(&mut self) -> impl Iterator<Item = (&String, &mut Value)>
Creates an iterator over mutable references to the entries.
Sourcepub fn remove(&mut self, key: impl AsRef<str>) -> Option<Value>
pub fn remove(&mut self, key: impl AsRef<str>) -> Option<Value>
Removes a key, returning the previous value, if any.
Trait Implementations§
Source§impl Clone for StoreState
impl Clone for StoreState
Source§fn clone(&self) -> StoreState
fn clone(&self) -> StoreState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for StoreState
impl Debug for StoreState
Source§impl Default for StoreState
impl Default for StoreState
Source§fn default() -> StoreState
fn default() -> StoreState
Source§impl<'de> Deserialize<'de> for StoreState
impl<'de> Deserialize<'de> for StoreState
Source§fn deserialize<D>(
deserializer: D,
) -> Result<StoreState, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<StoreState, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl From<&StoreState> for Value
impl From<&StoreState> for Value
Source§fn from(state: &StoreState) -> Value
fn from(state: &StoreState) -> Value
Source§impl<K, V> From<(K, V)> for StoreState
impl<K, V> From<(K, V)> for StoreState
Source§fn from(_: (K, V)) -> StoreState
fn from(_: (K, V)) -> StoreState
Source§impl From<StoreState> for Value
impl From<StoreState> for Value
Source§fn from(state: StoreState) -> Value
fn from(state: StoreState) -> Value
Source§impl<K, V> FromIterator<(K, V)> for StoreState
impl<K, V> FromIterator<(K, V)> for StoreState
Source§fn from_iter<I>(iter: I) -> StoreStatewhere
I: IntoIterator<Item = (K, V)>,
fn from_iter<I>(iter: I) -> StoreStatewhere
I: IntoIterator<Item = (K, V)>,
Source§impl Serialize for StoreState
impl Serialize for StoreState
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Auto Trait Implementations§
impl Freeze for StoreState
impl RefUnwindSafe for StoreState
impl Send for StoreState
impl Sync for StoreState
impl Unpin for StoreState
impl UnwindSafe for StoreState
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<'de, D, R> CommandArg<'de, R> for Dwhere
D: Deserialize<'de>,
R: Runtime,
impl<'de, D, R> CommandArg<'de, R> for Dwhere
D: Deserialize<'de>,
R: Runtime,
Source§fn from_command(command: CommandItem<'de, R>) -> Result<D, InvokeError>
fn from_command(command: CommandItem<'de, R>) -> Result<D, InvokeError>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more