]>
git.proxmox.com Git - cargo.git/blob - vendor/regex/src/error.rs
4 /// An error that occurred during parsing or compiling a regular expression.
5 #[derive(Clone, PartialEq)]
9 /// The compiled program exceeded the set size limit.
10 /// The argument is the size limit imposed.
11 CompiledTooBig(usize),
12 /// Hints that destructuring should not be exhaustive.
14 /// This enum may grow additional variants, so this makes sure clients
15 /// don't count on exhaustive matching. (Otherwise, adding a new variant
16 /// could break existing code.)
21 impl ::std
::error
::Error
for Error
{
22 // TODO: Remove this method entirely on the next breaking semver release.
24 fn description(&self) -> &str {
26 Error
::Syntax(ref err
) => err
,
27 Error
::CompiledTooBig(_
) => "compiled program too big",
28 Error
::__Nonexhaustive
=> unreachable
!(),
33 impl fmt
::Display
for Error
{
34 fn fmt(&self, f
: &mut fmt
::Formatter
<'_
>) -> fmt
::Result
{
36 Error
::Syntax(ref err
) => err
.fmt(f
),
37 Error
::CompiledTooBig(limit
) => write
!(
39 "Compiled regex exceeds size limit of {} bytes.",
42 Error
::__Nonexhaustive
=> unreachable
!(),
47 // We implement our own Debug implementation so that we show nicer syntax
48 // errors when people use `Regex::new(...).unwrap()`. It's a little weird,
49 // but the `Syntax` variant is already storing a `String` anyway, so we might
50 // as well format it nicely.
51 impl fmt
::Debug
for Error
{
52 fn fmt(&self, f
: &mut fmt
::Formatter
<'_
>) -> fmt
::Result
{
54 Error
::Syntax(ref err
) => {
55 let hr
: String
= repeat('
~'
).take(79).collect();
56 writeln
!(f
, "Syntax(")?
;
57 writeln
!(f
, "{}", hr
)?
;
58 writeln
!(f
, "{}", err
)?
;
59 writeln
!(f
, "{}", hr
)?
;
63 Error
::CompiledTooBig(limit
) => {
64 f
.debug_tuple("CompiledTooBig").field(&limit
).finish()
66 Error
::__Nonexhaustive
=> {
67 f
.debug_tuple("__Nonexhaustive").finish()