Skip to main content

Expected

Trait Expected 

Source
pub trait Expected {
    // Required method
    fn fmt(&self, formatter: &mut Formatter<'_>) -> Result<(), Error>;
}
Expand description

Expected represents an explanation of what data a Visitor was expecting to receive.

This is used as an argument to the invalid_type, invalid_value, and invalid_length methods of the Error trait to build error messages. The message should be a noun or noun phrase that completes the sentence โ€œThis Visitor expects to receive โ€ฆโ€, for example the message could be โ€œan integer between 0 and 64โ€. The message should not be capitalized and should not end with a period.

Within the context of a Visitor implementation, the Visitor itself (&self) is an implementation of this trait.

โ“˜
fn visit_bool<E>(self, v: bool) -> Result<Self::Value, E>
where
    E: de::Error,
{
    Err(de::Error::invalid_type(Unexpected::Bool(v), &self))
}

Outside of a Visitor, &"..." can be used.

โ“˜
return Err(de::Error::invalid_type(
    Unexpected::Bool(v),
    &"a negative integer",
));

Required Methodsยง

Source

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result<(), Error>

Format an explanation of what data was being expected. Same signature as the Display and Debug traits.

Trait Implementationsยง

Sourceยง

impl Display for dyn Expected + '_

Sourceยง

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Dyn Compatibilityยง

This trait is dyn compatible.

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

Implementations on Foreign Typesยง

Sourceยง

impl Expected for &str

Sourceยง

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result<(), Error>

ยง

impl Expected for ComponentRange

Available on crate feature serde only.

This trait implementation is deprecated and will be removed in a future breaking release.

ยง

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

Implementorsยง

Sourceยง

impl<'de, T> Expected for T
where T: Visitor<'de>,