rsv_core/
error.rs

1use std::fmt;
2use std::error::Error as StdError;
3use std::str::Utf8Error;
4// #[cfg(features = "serde")]
5use serde::ser::Error as SeError;
6use serde::de::Error as DeError;
7
8#[derive(Debug)]
9pub struct Error(pub ErrorKind);
10
11#[derive(Debug)]
12pub enum ErrorKind {
13    // #[cfg(features = "serde")]
14    Serialize(String),
15    Deserialize(String),
16    IO(String),
17}
18
19impl StdError for Error {}
20
21impl fmt::Display for Error {
22    fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result {
23        todo!()
24    }
25}
26
27// #[cfg(features = "serde")]
28impl SeError for Error {
29    fn custom<T: fmt::Display>(msg: T) -> Error {
30        Error(ErrorKind::Serialize(msg.to_string()))
31    }
32}
33
34// #[cfg(features = "serde")]
35impl DeError for Error {
36    fn custom<T: fmt::Display>(msg: T) -> Error {
37        Error(ErrorKind::Deserialize(msg.to_string()))
38    }
39}
40
41impl From<Utf8Error> for Error {
42    fn from(e: Utf8Error) -> Error {
43        Error(ErrorKind::Deserialize(e.to_string()))
44    }
45}
46
47impl From<std::io::Error> for Error {
48    fn from(e: std::io::Error) -> Error {
49        Error(ErrorKind::IO(e.kind().to_string()))
50    }
51}