]>
git.proxmox.com Git - rustc.git/blob - src/vendor/regex-0.2.11/src/error.rs
1 // Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
12 use std
::iter
::repeat
;
16 /// An error that occurred during parsing or compiling a regular expression.
17 #[derive(Clone, PartialEq)]
21 /// The compiled program exceeded the set size limit.
22 /// The argument is the size limit imposed.
23 CompiledTooBig(usize),
24 /// Hints that destructuring should not be exhaustive.
26 /// This enum may grow additional variants, so this makes sure clients
27 /// don't count on exhaustive matching. (Otherwise, adding a new variant
28 /// could break existing code.)
33 impl ::std
::error
::Error
for Error
{
34 fn description(&self) -> &str {
36 Error
::Syntax(ref err
) => err
,
37 Error
::CompiledTooBig(_
) => "compiled program too big",
38 Error
::__Nonexhaustive
=> unreachable
!(),
42 fn cause(&self) -> Option
<&::std
::error
::Error
> {
47 impl fmt
::Display
for Error
{
48 fn fmt(&self, f
: &mut fmt
::Formatter
) -> fmt
::Result
{
50 Error
::Syntax(ref err
) => err
.fmt(f
),
51 Error
::CompiledTooBig(limit
) => {
52 write
!(f
, "Compiled regex exceeds size limit of {} bytes.",
55 Error
::__Nonexhaustive
=> unreachable
!(),
60 // We implement our own Debug implementation so that we show nicer syntax
61 // errors when people use `Regex::new(...).unwrap()`. It's a little weird,
62 // but the `Syntax` variant is already storing a `String` anyway, so we might
63 // as well format it nicely.
64 impl fmt
::Debug
for Error
{
65 fn fmt(&self, f
: &mut fmt
::Formatter
) -> fmt
::Result
{
67 Error
::Syntax(ref err
) => {
68 let hr
: String
= repeat('
~'
).take(79).collect();
69 try
!(writeln
!(f
, "Syntax("));
70 try
!(writeln
!(f
, "{}", hr
));
71 try
!(writeln
!(f
, "{}", err
));
72 try
!(writeln
!(f
, "{}", hr
));
76 Error
::CompiledTooBig(limit
) => {
77 f
.debug_tuple("CompiledTooBig")
81 Error
::__Nonexhaustive
=> {
82 f
.debug_tuple("__Nonexhaustive").finish()
88 impl From
<syntax
::Error
> for Error
{
89 fn from(err
: syntax
::Error
) -> Error
{
90 Error
::Syntax(err
.to_string())