ValueScope

Struct ValueScope 

Source
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>

Source

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.

Source

pub fn fail_serialization(&mut self, error: impl Display)

Fail serialization with a custom error.

Source

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.

Auto Trait Implementations§

§

impl<'v, S> Freeze for ValueScope<'v, S>
where S: Freeze, <S as Serializer>::Ok: Freeze, <S as Serializer>::Error: Freeze,

§

impl<'v, S> RefUnwindSafe for ValueScope<'v, S>

§

impl<'v, S> Send for ValueScope<'v, S>
where S: Send, <S as Serializer>::Ok: Send, <S as Serializer>::Error: Send,

§

impl<'v, S> Sync for ValueScope<'v, S>
where S: Sync, <S as Serializer>::Ok: Sync, <S as Serializer>::Error: Sync,

§

impl<'v, S> Unpin for ValueScope<'v, S>
where S: Unpin, <S as Serializer>::Ok: Unpin, <S as Serializer>::Error: Unpin,

§

impl<'v, S> UnwindSafe for ValueScope<'v, S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.