Trait Error

Source
pub trait Error: Sized + Error {
    // Required method
    fn custom<T>(msg: T) -> Self
       where T: Display;
}
Expand description

Trait used by Serialize implementations to generically construct errors belonging to the Serializer against which they are currently running.

ยงExample implementation

The example data format presented on the website shows an error type appropriate for a basic JSON data format.

Required Methodsยง

Source

fn custom<T>(msg: T) -> Self
where T: Display,

Used when a Serialize implementation encounters any error while serializing a type.

The message should not be capitalized and should not end with a period.

For example, a filesystem Path may refuse to serialize itself if it contains invalid UTF-8 data.

โ“˜
use serde::ser::{self, Serialize, Serializer};

impl Serialize for Path {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
    {
        match self.to_str() {
            Some(s) => serializer.serialize_str(s),
            None => Err(ser::Error::custom("path contains invalid UTF-8 characters")),
        }
    }
}

Dyn Compatibilityยง

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Typesยง

Sourceยง

impl Error for EncodeError

Sourceยง

fn custom<T>(msg: T) -> EncodeError
where T: Display,

Sourceยง

impl Error for Error

Sourceยง

fn custom<T>(msg: T) -> Error
where T: Display,

ยง

impl Error for ConfigError

ยง

fn custom<T>(msg: T) -> ConfigError
where T: Display,

ยง

impl Error for Error

ยง

fn custom<T>(msg: T) -> Error
where T: Display,

ยง

impl Error for Error

ยง

fn custom<T>(msg: T) -> Error
where T: Display,

ยง

impl Error for Error

ยง

fn custom<T>(msg: T) -> Error
where T: Display,

ยง

impl Error for Error

ยง

fn custom<T>(msg: T) -> Error
where T: Display,

ยง

impl Error for SerializerError

ยง

fn custom<T>(_msg: T) -> SerializerError
where T: Display,

Implementorsยง

Sourceยง

impl Error for flams_router_vscode::server_fn::inventory::core::fmt::Error

Sourceยง

impl Error for flams_router_vscode::server_fn::serde::de::value::Error