pub struct Wrapper { /* private fields */ }Expand description
A stored entry containing the serialized representation and an optional cached runtime value.
serialized: theserde_value::Valueused for Serialize/Deserialize of the map.value: an optionalBox<dyn Any>holding the deserialized value. This field is not serialized and is cleared onCloneandDeserialize.
Semantics:
- On
insert, bothserializedandvalueare populated. - On access (
get/get_mut), the entry will lazily deserializeserializedintovalueif the cache is empty. into_innerattempts to extract the concrete type from the cache or by deserializing.
Notes:
- The cloning, serialization and deserialization happens based on the serialized
serde_value::Value, so any modifications to fields that are marked#[serde(skip)]will not be lost after a serialization round-trip, or after cloning the map. - Currently any modifications to the cached
valueare not reflected back into theserializedform, so serialization WILL reflect the original value only. This is a known limitation and is planned to be addressed in a future version by returning a Guard object that will update the serialized value on Drop.
Implementations§
Source§impl Wrapper
impl Wrapper
Sourcepub fn try_get<T>(&self) -> Option<&T>where
T: for<'de> Deserialize<'de> + 'static,
pub fn try_get<T>(&self) -> Option<&T>where
T: for<'de> Deserialize<'de> + 'static,
Attempt to get an immutable reference to the deserialized value of type T. Will return None
if the value has not yet been deserialized, as we need a mutable reference to mutate the
entry to save the deserialized value.
Sourcepub fn get<T>(&mut self) -> Result<&T, DeserializerError>where
T: Serialize + for<'de> Deserialize<'de> + 'static,
pub fn get<T>(&mut self) -> Result<&T, DeserializerError>where
T: Serialize + for<'de> Deserialize<'de> + 'static,
Attempt to get an immutable reference to the deserialized value of type T,
lazily deserializing if necessary. We need a mutable reference in order to save the
deserialized value to the entry
Sourcepub fn get_mut<'a, T>(
&'a mut self,
) -> Result<WriteGuard<'a, T>, DeserializerError>where
T: for<'de> Deserialize<'de> + Serialize + 'static,
pub fn get_mut<'a, T>(
&'a mut self,
) -> Result<WriteGuard<'a, T>, DeserializerError>where
T: for<'de> Deserialize<'de> + Serialize + 'static,
Attempt to an mutable reference to the deserialized value of type T,
lazily deserializing if necessary.
Sourcepub fn into_inner<T>(self) -> Result<T, DeserializerError>where
T: for<'de> Deserialize<'de> + 'static,
pub fn into_inner<T>(self) -> Result<T, DeserializerError>where
T: for<'de> Deserialize<'de> + 'static,
Attempt to extract the inner value by deserializing if necessary.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Wrapper
impl<'de> Deserialize<'de> for Wrapper
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Wrapper
impl !RefUnwindSafe for Wrapper
impl !Send for Wrapper
impl !Sync for Wrapper
impl Unpin for Wrapper
impl !UnwindSafe for Wrapper
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