regex_lite/error.rs
1/// An error that occurred during parsing or compiling a regular expression.
2///
3/// A parse error occurs when the syntax of the regex pattern is not
4/// valid. Otherwise, a regex can still fail to build if it would
5/// result in a machine that exceeds the configured size limit, via
6/// [`RegexBuilder::size_limit`](crate::RegexBuilder::size_limit).
7///
8/// This error type provides no introspection capabilities. The only thing you
9/// can do with it is convert it to a string as a human readable error message.
10#[derive(Clone, Debug, Eq, PartialEq)]
11pub struct Error {
12 msg: &'static str,
13}
14
15impl Error {
16 pub(crate) fn new(msg: &'static str) -> Error {
17 Error { msg }
18 }
19}
20
21#[cfg(feature = "std")]
22impl std::error::Error for Error {}
23
24impl core::fmt::Display for Error {
25 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
26 write!(f, "{}", self.msg)
27 }
28}