1use core::fmt;
8pub use std::error::Error as StdError;
9use std::io;
10
11pub trait Error: Sized + StdError + From<io::Error> {
12 fn with_kind(self, kind: &'static str) -> Self;
13
14 fn custom<T: fmt::Display>(msg: T) -> Self;
16
17 fn invalid_type<U: fmt::Display, E: fmt::Display>(unexp: U, exp: E) -> Self {
19 Self::custom(format_args!("invalid type: {}, expected {}", unexp, exp))
20 }
21
22 fn invalid_value<U: fmt::Display, E: fmt::Display>(unexp: U, exp: E) -> Self {
25 Self::custom(format_args!("invalid value: {}, expected {}", unexp, exp))
26 }
27
28 fn invalid_length<E: fmt::Display>(len: usize, exp: E) -> Self {
31 Self::custom(format_args!("invalid length: {}, expected {}", len, exp))
32 }
33}