pub struct Derived;Expand description
The adapter that uses the derived implementation of a type.
Adapters on a type (see container adapters)
replace its derived implementation. Adapters which wrap another
adapter can wrap the derived implementation with Derived, which is
written as _ in the attribute. This is how values are checked or converted after the
derived implementation deserialized them:
use deser::{Deserialize, State};
use deser::de::SinkHandle;
/// Deserializes with `A`, missing values are the default.
pub struct DefaultIfMissing<A>(std::marker::PhantomData<A>);
impl<'de, T: Default + Send, A: Deserialize<'de, T>> Deserialize<'de, T>
for DefaultIfMissing<A>
{
fn deserialize_into<'out>(
out: &'out mut Option<T>,
state: &mut State,
) -> SinkHandle<'out, 'de> {
A::deserialize_into(out, state)
}
fn initial_value() -> Option<T> {
Some(T::default())
}
}
#[derive(Deserialize, Default)]
#[deser(deserialize_as = DefaultIfMissing<_>)]
struct Limits {
max_connections: u32,
}
#[derive(Deserialize)]
struct Config {
limits: Limits,
}
// the limits are missing
let config: Config = deser_json::from_str("{}").unwrap();
assert_eq!(config.limits.max_connections, 0);The derived implementation is only available through this adapter for
the directions that have an adapter with _.
Trait Implementations§
Source§impl<'de, T: DerivedDeserialize<'de>> Deserialize<'de, T> for Derived
impl<'de, T: DerivedDeserialize<'de>> Deserialize<'de, T> for Derived
Source§fn deserialize_into<'out>(
out: &'out mut Option<T>,
state: &mut State,
) -> SinkHandle<'out, 'de>
fn deserialize_into<'out>( out: &'out mut Option<T>, state: &mut State, ) -> SinkHandle<'out, 'de>
Creates a sink that deserializes the value into the given slot. Read more
Source§fn expecting() -> Cow<'static, str>
fn expecting() -> Cow<'static, str>
Returns what the value expects, for error messages. Read more
Source§fn describe_type(d: &mut dyn Describe)
fn describe_type(d: &mut dyn Describe)
Describes the Rust shape of the type. Read more
Source§fn initial_value() -> Option<T>
fn initial_value() -> Option<T>
Provides the value of a missing struct field. Read more
Source§fn deserialize_update<'out>(
value: &'out mut T,
state: &mut State,
) -> SinkHandle<'out, 'de>
fn deserialize_update<'out>( value: &'out mut T, state: &mut State, ) -> SinkHandle<'out, 'de>
Creates a sink that updates an existing value. Read more
Source§impl<T: DerivedSerialize + ?Sized> Serialize<T> for Derived
impl<T: DerivedSerialize + ?Sized> Serialize<T> for Derived
Source§fn serialize<'a>(value: &'a T, state: &mut State) -> Result<Emit<'a>, Error>
fn serialize<'a>(value: &'a T, state: &mut State) -> Result<Emit<'a>, Error>
Serializes the value.
Source§fn finish(value: &T, state: &mut State) -> Result<(), Error>
fn finish(value: &T, state: &mut State) -> Result<(), Error>
Invoked after the serialization finished. Read more
Source§fn container_shape(value: &T) -> ContainerShape
fn container_shape(value: &T) -> ContainerShape
Returns the shape of the value if it’s a map or sequence. Read more
Auto Trait Implementations§
impl Freeze for Derived
impl RefUnwindSafe for Derived
impl Send for Derived
impl Sync for Derived
impl Unpin for Derived
impl UnsafeUnpin for Derived
impl UnwindSafe for Derived
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