pub struct ValueScope<'v, S: Serializer> { /* private fields */ }Expand description
Inspect and modify serialized values.
See Hooks::on_value.
Implementations§
Source§impl<'v, S: Serializer> ValueScope<'v, S>
impl<'v, S: Serializer> ValueScope<'v, S>
Sourcepub fn value(&self) -> &Value<'_>
pub fn value(&self) -> &Value<'_>
Returns the serialized value.
Primitive values, like numbers, will have the actual value copied to the scope, whilst for compound values, like structs, only metadata is available.
Sourcepub fn fail_serialization(&mut self, error: impl Display)
pub fn fail_serialization(&mut self, error: impl Display)
Fail serialization with a custom error.
Sourcepub fn replace<T: Serialize + ?Sized>(&mut self, new_value: &T) -> &mut Self
pub fn replace<T: Serialize + ?Sized>(&mut self, new_value: &T) -> &mut Self
Replace the value with another serializable value.
The new value is fed directly into the serializer.
There is no requirement for the new value to be of the same type. However, the serializer you use can have restrictions on compatibility.
Hooks will not be called for the serialization of the new value. If you want to
attach hooks to the new value as well, you need to explicitly do it by calling
ser::hook() on it.
§Panics
A value can only be replaced once. This method will panic if the value has already been replaced.