decoder

Attribute Macro decoder 

Source
#[decoder]
Expand description

This is an attribute macro that must be used when implementing a Decoder.

It is required to use because a Decoder implementation might introduce new associated types in the future, and this is not yet supported on a language level in Rust. So this attribute macro polyfills any missing types automatically.

Note that if the Cx or Mode associated types are not specified, they will be defaulted to any type parameters which starts with the uppercase C or M respectively.

Note that using derives directly from musli_core requires you to use the #[musli_core::decoder(crate = musli_core)] attribute.

ยงExamples

use std::fmt;
use std::marker::PhantomData;

use musli_core::Context;
use musli_core::de::{Decoder, Decode};

struct MyDecoder<C, M> {
    cx: C,
    _marker: PhantomData<M>,
}

#[musli_core::decoder(crate = musli_core)]
impl<'de, C, M> Decoder<'de> for MyDecoder<C, M>
where
    C: Context,
    M: 'static,
{
    #[inline]
    fn expecting(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "32-bit unsigned integers")
    }

    #[inline]
    fn decode_u32(self) -> Result<u32, Self::Error> {
        Ok(42)
    }
}