Attribute Macro musli::visitor

source ·
#[visitor]
Expand description

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

It is required to use because a Visitor 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.

§Examples

use std::fmt;

use musli::Context;
use musli::de::Visitor;

struct AnyVisitor;

#[musli::visitor]
impl<'de, C: ?Sized + Context> Visitor<'de, C> for AnyVisitor {
    type Ok = ();

    #[inline]
    fn expecting(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(
            f,
            "value that can be decoded into dynamic container"
        )
    }
}

Please refer to the main musli documentation.