Skip to main content

flussab_btor2/
error.rs

1use std::io;
2
3pub use flussab::text::SyntaxError;
4use thiserror::Error;
5
6/// Either a [`SyntaxError`] or an [`io::Error`].
7///
8/// This is used via [`ParseError`], which wraps this in a [`Box`].
9#[derive(Error, Debug)]
10pub enum InnerParseError {
11    /// A syntax error containing a message and a source location.
12    #[error(transparent)]
13    SyntaxError(SyntaxError),
14    /// An IO error.
15    #[error("IO error during parsing: {}", .0)]
16    IoError(#[source] io::Error),
17}
18
19/// Boxed version of [`InnerParseError`].
20pub type ParseError = Box<InnerParseError>;
21
22impl From<io::Error> for ParseError {
23    fn from(err: io::Error) -> Self {
24        Box::new(InnerParseError::IoError(err))
25    }
26}
27
28impl From<SyntaxError> for ParseError {
29    fn from(err: SyntaxError) -> Self {
30        Box::new(InnerParseError::SyntaxError(err))
31    }
32}