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 fn description(&self) -> &str {
23 match *self {
24 Error::Syntax(ref err) => err,
25 Error::CompiledTooBig(_) => "compiled program too big",
26 Error::__Nonexhaustive => unreachable!(),
27 }
28 }
29}
30
31impl fmt::Display for Error {
32 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
33 match *self {
34 Error::Syntax(ref err) => err.fmt(f),
35 Error::CompiledTooBig(limit) => write!(
36 f,
37 "Compiled regex exceeds size limit of {} bytes.",
38 limit
39 ),
40 Error::__Nonexhaustive => unreachable!(),
41 }
42 }
43}
44
45impl fmt::Debug for Error {
50 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
51 match *self {
52 Error::Syntax(ref err) => {
53 let hr: String = repeat('~').take(79).collect();
54 writeln!(f, "Syntax(")?;
55 writeln!(f, "{}", hr)?;
56 writeln!(f, "{}", err)?;
57 writeln!(f, "{}", hr)?;
58 write!(f, ")")?;
59 Ok(())
60 }
61 Error::CompiledTooBig(limit) => {
62 f.debug_tuple("CompiledTooBig").field(&limit).finish()
63 }
64 Error::__Nonexhaustive => {
65 f.debug_tuple("__Nonexhaustive").finish()
66 }
67 }
68 }
69}