1use std::fmt;
2use std::iter::repeat;
3
4#[derive(Clone, PartialEq)]
6pub enum Error {
7 Syntax(String),
9 CompiledTooBig(usize),
12 #[doc(hidden)]
18 __Nonexhaustive,
19}
20
21impl ::std::error::Error for Error {
22 #[allow(deprecated)]
24 fn description(&self) -> &str {
25 match *self {
26 Error::Syntax(ref err) => err,
27 Error::CompiledTooBig(_) => "compiled program too big",
28 Error::__Nonexhaustive => unreachable!(),
29 }
30 }
31}
32
33impl fmt::Display for Error {
34 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
35 match *self {
36 Error::Syntax(ref err) => err.fmt(f),
37 Error::CompiledTooBig(limit) => write!(
38 f,
39 "Compiled regex exceeds size limit of {} bytes.",
40 limit
41 ),
42 Error::__Nonexhaustive => unreachable!(),
43 }
44 }
45}
46
47impl fmt::Debug for Error {
52 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
53 match *self {
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)?;
60 write!(f, ")")?;
61 Ok(())
62 }
63 Error::CompiledTooBig(limit) => {
64 f.debug_tuple("CompiledTooBig").field(&limit).finish()
65 }
66 Error::__Nonexhaustive => {
67 f.debug_tuple("__Nonexhaustive").finish()
68 }
69 }
70 }
71}