Skip to content
Myr

error.rs

This file

Path

crates/pcre2/src/error.rs

48 lines · 1.3 KiB · Rust

Last changed by

Not known.

History of this file

Take it

1/// An error that can occur in this crate.2///3/// Generally, this error corresponds to problems building a regular4/// expression, whether it's in parsing, compilation or a problem with5/// guaranteeing a configured optimization.6#[derive(Clone, Debug)]7pub struct Error {8    kind: ErrorKind,9}1011impl Error {12    pub(crate) fn regex<E: std::error::Error>(err: E) -> Error {13        Error { kind: ErrorKind::Regex(err.to_string()) }14    }1516    /// Return the kind of this error.17    pub fn kind(&self) -> &ErrorKind {18        &self.kind19    }20}2122/// The kind of an error that can occur.23#[derive(Clone, Debug)]24#[non_exhaustive]25pub enum ErrorKind {26    /// An error that occurred as a result of parsing a regular expression.27    /// This can be a syntax error or an error that results from attempting to28    /// compile a regular expression that is too big.29    ///30    /// The string here is the underlying error converted to a string.31    Regex(String),32}3334impl std::error::Error for Error {35    fn description(&self) -> &str {36        match self.kind {37            ErrorKind::Regex(_) => "regex error",38        }39    }40}4142impl std::fmt::Display for Error {43    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {44        match self.kind {45            ErrorKind::Regex(ref s) => write!(f, "{}", s),46        }47    }48}