sqlite_collections/ds/set/
error.rs

1use crate::format::Format;
2use std::fmt;
3
4pub enum Error<S>
5where
6    S: Format,
7{
8    Sqlite(rusqlite::Error),
9    Fmt(std::fmt::Error),
10    Serialize(S::SerializeError),
11    Deserialize(S::DeserializeError),
12}
13
14impl<S> fmt::Debug for Error<S>
15where
16    S: Format,
17{
18    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19        match self {
20            Error::Sqlite(e) => write!(f, "Error::Sqlite({e:?})"),
21            Error::Fmt(e) => write!(f, "Error::Fmt({e:?})"),
22            Error::Serialize(e) => write!(f, "Error::Serialize({e:?})"),
23            Error::Deserialize(e) => write!(f, "Error::Deserialize({e:?})"),
24        }
25    }
26}
27
28impl<S> From<std::fmt::Error> for Error<S>
29where
30    S: Format,
31{
32    fn from(v: std::fmt::Error) -> Self {
33        Self::Fmt(v)
34    }
35}
36
37impl<S> From<rusqlite::Error> for Error<S>
38where
39    S: Format,
40{
41    fn from(v: rusqlite::Error) -> Self {
42        Self::Sqlite(v)
43    }
44}
45
46impl<S> fmt::Display for Error<S>
47where
48    S: Format,
49{
50    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
51        match self {
52            Error::Sqlite(e) => write!(f, "sqlite error: {e}"),
53            Error::Fmt(e) => write!(f, "fmt error: {e}"),
54            Error::Serialize(e) => write!(f, "serialize error: {e}"),
55            Error::Deserialize(e) => write!(f, "deserialize error: {e}"),
56        }
57    }
58}
59
60impl<S> std::error::Error for Error<S> where S: Format {}