grit_util/
error.rs

1use regex::Error as RegexError;
2use std::io::{self};
3use std::num::{ParseFloatError, ParseIntError};
4use std::str::Utf8Error;
5use std::string::FromUtf8Error;
6use thiserror::Error;
7
8#[derive(Error, Debug)]
9pub enum GritPatternError {
10    #[error("Matcher: {0}")]
11    Matcher(String),
12
13    #[error(transparent)]
14    Io(#[from] io::Error),
15
16    #[error(transparent)]
17    ParseFloat(#[from] ParseFloatError),
18
19    #[error(transparent)]
20    ParseInt(#[from] ParseIntError),
21
22    #[error(transparent)]
23    Regex(#[from] RegexError),
24
25    #[error(transparent)]
26    Utf8(#[from] Utf8Error),
27
28    #[error(transparent)]
29    FromUtf8(#[from] FromUtf8Error),
30
31    #[error("[Builder] {0}")]
32    Builder(String),
33
34    #[error("{0}")]
35    Generic(String),
36}
37
38impl GritPatternError {
39    pub fn new_matcher(reason: impl Into<String>) -> Self {
40        Self::Matcher(reason.into())
41    }
42
43    pub fn new(reason: impl Into<String>) -> Self {
44        Self::Generic(reason.into())
45    }
46}
47
48pub type GritResult<R> = Result<R, GritPatternError>;