serde_hashkey/
error.rs
1use serde::{de, ser};
3use std::{error, fmt, result};
4
5#[derive(Debug, PartialEq)]
8pub enum Error {
9 Unexpected(&'static str),
11 UnsupportedType(&'static str),
13 UnexpectedVariant(&'static str),
15 Custom(String),
17 MissingValue,
19 InvalidLength,
21}
22
23pub type Result<T, E = Error> = result::Result<T, E>;
25
26impl fmt::Display for Error {
27 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
28 use self::Error::*;
29
30 match self {
31 Unexpected(expected) => write!(fmt, "unexpected type, expected: {}", expected),
32 UnsupportedType(ty) => write!(fmt, "unsupported type: {}", ty),
33 UnexpectedVariant(variant) => write!(fmt, "unexpectec variant: {}", variant),
34 Custom(e) => write!(fmt, "{}", e),
35 MissingValue => write!(fmt, "missing value duration deserialization"),
36 InvalidLength => write!(fmt, "array with invalid length"),
37 }
38 }
39}
40
41impl error::Error for Error {}
42
43impl ser::Error for Error {
44 fn custom<T>(msg: T) -> Self
45 where
46 T: fmt::Display,
47 {
48 Error::Custom(msg.to_string())
49 }
50}
51
52impl de::Error for Error {
53 fn custom<T>(msg: T) -> Self
54 where
55 T: fmt::Display,
56 {
57 Error::Custom(msg.to_string())
58 }
59}