serde_url_params/
error.rs1use serde::ser;
4use std::fmt;
5
6#[derive(Debug)]
7pub enum Error {
10 Extern(Box<dyn std::error::Error + Send + Sync>),
12 Unsupported(String),
14 Custom(String),
16}
17
18pub type Result<T> = std::result::Result<T, Error>;
20
21impl Error {
22 pub fn unsupported<T: fmt::Display>(msg: T) -> Self {
25 Error::Unsupported(format!("{}", msg))
26 }
27}
28
29impl fmt::Display for Error {
30 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
31 match *self {
32 Error::Extern(ref err) => fmt::Display::fmt(err, f),
33 Error::Unsupported(ref msg) | Error::Custom(ref msg) => fmt::Display::fmt(msg, f),
34 }
35 }
36}
37
38impl std::error::Error for Error {}
39
40impl ser::Error for Error {
41 fn custom<T: fmt::Display>(msg: T) -> Error {
42 Error::Custom(msg.to_string())
43 }
44}
45
46impl From<std::io::Error> for Error {
47 fn from(err: std::io::Error) -> Self {
48 Error::Extern(Box::new(err))
49 }
50}
51
52impl From<std::string::FromUtf8Error> for Error {
53 fn from(err: std::string::FromUtf8Error) -> Self {
54 Error::Extern(Box::new(err))
55 }
56}