rs-common 0.1.0

The basics of the rs-toolbox project. Contains common code between repositories.
Documentation
use thiserror::Error;

pub type Code = &'static str;

#[derive(Error, Debug)]
pub enum Error {
    /// A lexical error occurs when a lexer ( first step in compilation ) can not continue tokenizing
    /// this does not mean that the program is invalid, if that is the case an Error Token will be
    /// returned, instead this only occurs when the lexer absolutely can not continue tokenizing. This
    /// is usually due to an unhandeled character or something similar.
    #[error("An error occured during lexical analysis. 1{0}: {1}")]
    LexicalError(Code, &'static str),

    /// A syntactical error occurs when a parser can't continue parsing the program. This is usually
    /// due to an unexpected or missing token, but can also be due to anything that could later lead to
    /// a runtime error.
    #[error("An error occured during syntactical analysis. 2{0}: {1}")]
    SyntacticalError(Code, &'static str),

    /// An IO error occurs when there's a problem with reading ( input ) or writing ( output ) to a source.
    /// This is usually due to the source not existing, being read or write protected, or being corrupted.
    #[error("An error occured during I/O. 3{0}: {1}")]
    IOError(Code, &'static str),

    /// An initialisation error occurs when somethings fails to be initialised. This can have miscellaneous
    /// causes, but is usually due to a lack of memory or invalid arguments.
    #[error("An error occured during initialisation. 4{0}: {1}")]
    InitialisationError(Code, &'static str),
}

impl<T> From<Error> for Result<T, Error> {
    fn from(err: Error) -> Result<T, Error> {
        Err(err)
    }
}