1use std::error::Error as StdError;
4
5#[derive(thiserror::Error, Debug)]
7pub enum Error {
8 #[error("{context}: {source}")]
10 Context {
11 context: String,
12 #[source]
13 source: Box<dyn StdError + Send + Sync>,
14 },
15
16 #[error("{0}")]
18 Message(String),
19}
20
21impl Error {
22 pub fn msg(msg: impl Into<String>) -> Self {
24 Self::Message(msg.into())
25 }
26
27 pub fn context(
29 context: impl Into<String>,
30 source: impl StdError + Send + Sync + 'static,
31 ) -> Self {
32 Self::Context {
33 context: context.into(),
34 source: Box::new(source),
35 }
36 }
37}
38
39pub type Result<T> = std::result::Result<T, Error>;