1use std::fmt::Display;
2
3use derive_more::From;
4
5pub type Result<T> = core::result::Result<T, Error>;
6
7#[derive(Debug, From)]
8pub enum Error {
9 #[from(String, &String, &str)]
10 Custom(String),
11
12 #[from]
14 Io(std::io::Error),
15
16 #[from]
17 Sql(sqlx::error::Error),
18
19 #[from]
20 Migrate(sqlx::migrate::MigrateError),
21}
22
23impl Error {
26 pub fn custom_from_err(err: impl std::error::Error) -> Self {
27 Self::Custom(err.to_string())
28 }
29
30 pub fn custom(val: impl Into<String>) -> Self {
31 Self::Custom(val.into())
32 }
33}
34
35impl Display for Error {
40 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41 writeln!(f, "{self:?}")
42 }
43}
44
45impl std::error::Error for Error {}
46
47