Skip to main content

Visitor

Trait Visitor 

Source
pub trait Visitor<'de, C>: Sized
where C: Context<Error = Self::Error, Allocator = Self::Allocator>,
{ type Ok; type Error; type Allocator: Allocator; type String: UnsizedVisitor<'de, C, str, Ok = Self::Ok, Error = Self::Error, Allocator = Self::Allocator>; type Bytes: UnsizedVisitor<'de, C, [u8], Ok = Self::Ok, Error = Self::Error, Allocator = Self::Allocator>;
Show 26 methods // Required method fn expecting(&self, f: &mut Formatter<'_>) -> Result; // Provided methods fn visit_empty(self, cx: C) -> Result<Self::Ok, Self::Error> { ... } fn visit_bool(self, cx: C, _: bool) -> Result<Self::Ok, Self::Error> { ... } fn visit_char(self, cx: C, _: char) -> Result<Self::Ok, Self::Error> { ... } fn visit_u8(self, cx: C, _: u8) -> Result<Self::Ok, Self::Error> { ... } fn visit_u16(self, cx: C, _: u16) -> Result<Self::Ok, Self::Error> { ... } fn visit_u32(self, cx: C, _: u32) -> Result<Self::Ok, Self::Error> { ... } fn visit_u64(self, cx: C, _: u64) -> Result<Self::Ok, Self::Error> { ... } fn visit_u128(self, cx: C, _: u128) -> Result<Self::Ok, Self::Error> { ... } fn visit_i8(self, cx: C, _: i8) -> Result<Self::Ok, Self::Error> { ... } fn visit_i16(self, cx: C, _: i16) -> Result<Self::Ok, Self::Error> { ... } fn visit_i32(self, cx: C, _: i32) -> Result<Self::Ok, Self::Error> { ... } fn visit_i64(self, cx: C, _: i64) -> Result<Self::Ok, Self::Error> { ... } fn visit_i128(self, cx: C, _: i128) -> Result<Self::Ok, Self::Error> { ... } fn visit_usize(self, cx: C, _: usize) -> Result<Self::Ok, Self::Error> { ... } fn visit_isize(self, cx: C, _: isize) -> Result<Self::Ok, Self::Error> { ... } fn visit_f32(self, cx: C, _: f32) -> Result<Self::Ok, Self::Error> { ... } fn visit_f64(self, cx: C, _: f64) -> Result<Self::Ok, Self::Error> { ... } fn visit_none(self, cx: C) -> Result<Self::Ok, Self::Error> { ... } fn visit_some<D>(self, decoder: D) -> Result<Self::Ok, Self::Error> where D: Decoder<'de, Cx = C, Error = C::Error, Allocator = C::Allocator> { ... } fn visit_sequence<D>(self, decoder: &mut D) -> Result<Self::Ok, Self::Error> where D: ?Sized + SequenceDecoder<'de, Cx = C, Error = Self::Error, Allocator = Self::Allocator> { ... } fn visit_map<D>(self, decoder: &mut D) -> Result<Self::Ok, Self::Error> where D: ?Sized + MapDecoder<'de, Cx = C, Error = Self::Error, Allocator = Self::Allocator> { ... } fn visit_string( self, cx: C, hint: SizeHint, ) -> Result<Self::String, Self::Error> { ... } fn visit_bytes( self, cx: C, hint: SizeHint, ) -> Result<Self::Bytes, Self::Error> { ... } fn visit_variant<D>(self, decoder: &mut D) -> Result<Self::Ok, Self::Error> where D: ?Sized + VariantDecoder<'de, Cx = C, Error = C::Error, Allocator = C::Allocator> { ... } fn visit_unknown<D>(self, decoder: D) -> Result<Self::Ok, D::Error> where D: Decoder<'de, Cx = C, Error = C::Error, Allocator = C::Allocator> { ... }
}
Expand description

Visitor capable of decoding any type into a value Visitor::Ok.

When implementing this trait you must use the #[musli::trait_defaults] attribute macro.

Each callback on this visitor indicates the type that should be decoded from the passed in decoder. A typical implementation would simply call the corresponding decoder function for the type being visited.

§Examples

use std::fmt;

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

struct AnyVisitor;

#[musli::trait_defaults]
impl<'de, C> Visitor<'de, C> for AnyVisitor
where
    C: Context,
{
    type Ok = ();

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

Required Associated Types§

Source

type Ok

The value produced by the visitor.

Source

type Error

The error produced by the visitor.

Source

type Allocator: Allocator

The allocator associated with the visitor.

Source

type String: UnsizedVisitor<'de, C, str, Ok = Self::Ok, Error = Self::Error, Allocator = Self::Allocator>

String decoder to use.

Source

type Bytes: UnsizedVisitor<'de, C, [u8], Ok = Self::Ok, Error = Self::Error, Allocator = Self::Allocator>

Bytes decoder to use.

Required Methods§

Source

fn expecting(&self, f: &mut Formatter<'_>) -> Result

Format the human-readable message that should occur if the decoder was expecting to decode some specific kind of value.

Provided Methods§

Source

fn visit_empty(self, cx: C) -> Result<Self::Ok, Self::Error>

Indicates that the visited type is empty.

Source

fn visit_bool(self, cx: C, _: bool) -> Result<Self::Ok, Self::Error>

Indicates that the visited type is a bool.

Source

fn visit_char(self, cx: C, _: char) -> Result<Self::Ok, Self::Error>

Indicates that the visited type is a char.

Source

fn visit_u8(self, cx: C, _: u8) -> Result<Self::Ok, Self::Error>

Indicates that the visited type is a u8.

Source

fn visit_u16(self, cx: C, _: u16) -> Result<Self::Ok, Self::Error>

Indicates that the visited type is a u16.

Source

fn visit_u32(self, cx: C, _: u32) -> Result<Self::Ok, Self::Error>

Indicates that the visited type is a u32.

Source

fn visit_u64(self, cx: C, _: u64) -> Result<Self::Ok, Self::Error>

Indicates that the visited type is a u64.

Source

fn visit_u128(self, cx: C, _: u128) -> Result<Self::Ok, Self::Error>

Indicates that the visited type is a u128.

Source

fn visit_i8(self, cx: C, _: i8) -> Result<Self::Ok, Self::Error>

Indicates that the visited type is a i8.

Source

fn visit_i16(self, cx: C, _: i16) -> Result<Self::Ok, Self::Error>

Indicates that the visited type is a i16.

Source

fn visit_i32(self, cx: C, _: i32) -> Result<Self::Ok, Self::Error>

Indicates that the visited type is a i32.

Source

fn visit_i64(self, cx: C, _: i64) -> Result<Self::Ok, Self::Error>

Indicates that the visited type is a i64.

Source

fn visit_i128(self, cx: C, _: i128) -> Result<Self::Ok, Self::Error>

Indicates that the visited type is a i128.

Source

fn visit_usize(self, cx: C, _: usize) -> Result<Self::Ok, Self::Error>

Indicates that the visited type is a usize.

Source

fn visit_isize(self, cx: C, _: isize) -> Result<Self::Ok, Self::Error>

Indicates that the visited type is a isize.

Source

fn visit_f32(self, cx: C, _: f32) -> Result<Self::Ok, Self::Error>

Indicates that the visited type is a f32.

Source

fn visit_f64(self, cx: C, _: f64) -> Result<Self::Ok, Self::Error>

Indicates that the visited type is a f64.

Source

fn visit_none(self, cx: C) -> Result<Self::Ok, Self::Error>

Indicates that the visited type is an optional value that is absent.

Source

fn visit_some<D>(self, decoder: D) -> Result<Self::Ok, Self::Error>
where D: Decoder<'de, Cx = C, Error = C::Error, Allocator = C::Allocator>,

Indicates that the visited type is an optional value that is present.

Source

fn visit_sequence<D>(self, decoder: &mut D) -> Result<Self::Ok, Self::Error>
where D: ?Sized + SequenceDecoder<'de, Cx = C, Error = Self::Error, Allocator = Self::Allocator>,

Indicates that the visited type is a sequence.

Source

fn visit_map<D>(self, decoder: &mut D) -> Result<Self::Ok, Self::Error>
where D: ?Sized + MapDecoder<'de, Cx = C, Error = Self::Error, Allocator = Self::Allocator>,

Indicates that the visited type is a map.

Source

fn visit_string( self, cx: C, hint: SizeHint, ) -> Result<Self::String, Self::Error>

Indicates that the visited type is string.

Source

fn visit_bytes(self, cx: C, hint: SizeHint) -> Result<Self::Bytes, Self::Error>

Indicates that the visited type is bytes.

Source

fn visit_variant<D>(self, decoder: &mut D) -> Result<Self::Ok, Self::Error>
where D: ?Sized + VariantDecoder<'de, Cx = C, Error = C::Error, Allocator = C::Allocator>,

Indicates that the visited type is a variant.

Source

fn visit_unknown<D>(self, decoder: D) -> Result<Self::Ok, D::Error>
where D: Decoder<'de, Cx = C, Error = C::Error, Allocator = C::Allocator>,

Indicates that the encoding does not support dynamic types.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§