Macro serde::forward_to_deserialize [] [src]

macro_rules! forward_to_deserialize {
    ($($func:ident)*) => { ... };
}

Helper macro when implementing the Deserializer part of a new data format for Serde.

Some Deserializer implementations for self-describing formats do not care what hint the Visitor gives them, they just want to blindly call the Visitor method corresponding to the data they can tell is in the input. This requires repetitive implementations of all the Deserializer trait methods.

#[inline]
fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Self::Error>
    where V: Visitor
{
    self.deserialize(visitor)
}

The forward_to_deserialize! macro implements these simple forwarding methods so that they forward directly to Deserializer::deserialize. You can choose which methods to forward.

impl Deserializer for MyDeserializer {
    fn deserialize<V>(self, visitor: V) -> Result<V::Value, Self::Error>
        where V: Visitor
    {
        /* ... */
    }

    forward_to_deserialize! {
        bool u8 u16 u32 u64 i8 i16 i32 i64 f32 f64 char str string unit option
        seq seq_fixed_size bytes byte_buf map unit_struct newtype_struct
        tuple_struct struct struct_field tuple enum ignored_any
    }
}