Skip to content

Commit 7de4a41

Browse files
committed
Implement Error
Fixes #44
1 parent 47bfbd1 commit 7de4a41

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/lib.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use std::io::prelude::*;
3333
use std::io;
3434
use std::path::{self, Path, PathBuf, Component};
3535
use std::str::FromStr;
36+
use std::error::Error;
3637

3738
use PatternToken::{Char, AnyChar, AnySequence, AnyRecursiveSequence, AnyWithin};
3839
use PatternToken::AnyExcept;
@@ -230,6 +231,15 @@ impl GlobError {
230231
pub fn error(&self) -> &io::Error { &self.error }
231232
}
232233

234+
impl Error for GlobError {
235+
fn description(&self) -> &str {
236+
self.error.description()
237+
}
238+
fn cause(&self) -> Option<&Error> {
239+
Some(&self.error)
240+
}
241+
}
242+
233243
impl fmt::Display for GlobError {
234244
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
235245
write!(f, "attempting to read `{}` resulted in an error: {}",
@@ -353,6 +363,12 @@ pub struct PatternError {
353363
pub msg: &'static str,
354364
}
355365

366+
impl Error for PatternError {
367+
fn description(&self) -> &str {
368+
self.msg
369+
}
370+
}
371+
356372
impl fmt::Display for PatternError {
357373
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
358374
write!(f, "Pattern syntax error near position {}: {}",

0 commit comments

Comments
 (0)