1use std::fmt;
2
3#[derive(Debug, thiserror::Error)]
4pub enum Error {
5 #[error("{0}")]
6 Message(String),
7 #[error(transparent)]
8 Io(#[from] std::io::Error),
9}
10
11impl Error {
12 pub fn msg(s: impl fmt::Display) -> Self {
13 Self::Message(s.to_string())
14 }
15}
16
17pub type Result<T> = std::result::Result<T, Error>;
18
19#[cfg(test)]
20mod tests {
21 use super::*;
22 use runi_test::prelude::*;
23 use runi_test::pretty_assertions::assert_eq;
24
25 #[rstest]
26 #[case("something went wrong")]
27 #[case("another error")]
28 fn error_from_string(#[case] msg: &str) {
29 let e = Error::msg(msg);
30 assert_eq!(e.to_string(), msg);
31 }
32
33 #[test]
34 fn result_with_error() {
35 let r: Result<()> = Err(Error::msg("fail"));
36 assert!(r.is_err());
37 }
38}