mini_lang/
error.rs

1use peg::{error::ParseError, str::LineCol};
2
3/// The result type for this crate.
4pub type MiniResult<T> = Result<T, MiniError>;
5
6/// The error type for this crate.
7#[derive(thiserror::Error, Debug)]
8pub enum MiniError {
9    #[error("Parse Error: {0}")]
10    Parse(ParseError<LineCol>),
11    #[error("Execution Error: {0}")]
12    Execution(String),
13    #[error("{0}")]
14    Any(Box<dyn std::error::Error>),
15}
16
17impl MiniError {
18    /// Put any kinds of error into `MiniError`.
19    pub fn from_error<E: std::error::Error + 'static>(error: E) -> Self {
20        Self::Any(Box::new(error))
21    }
22}
23
24impl<T: Into<String>> From<T> for MiniError {
25    fn from(s: T) -> Self {
26        Self::Execution(s.into())
27    }
28}