ooroo 0.1.0

A fast, compiled rule engine with a text-based DSL
Documentation
use std::fmt;

/// Errors produced when parsing DSL input.
#[derive(Debug)]
pub struct ParseError {
    message: String,
}

impl ParseError {
    pub(crate) fn new(message: impl Into<String>) -> Self {
        Self {
            message: message.into(),
        }
    }
}

impl fmt::Display for ParseError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "parse error: {}", self.message)
    }
}

impl std::error::Error for ParseError {}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn error_display() {
        let err = ParseError::new("unexpected token");
        assert_eq!(err.to_string(), "parse error: unexpected token");
    }
}