diff options
author | Andrew Gallant <jamslam@gmail.com> | 2020-01-11 20:27:20 +0300 |
---|---|---|
committer | Andrew Gallant <jamslam@gmail.com> | 2020-01-11 20:28:57 +0300 |
commit | 64367023b1a8675f8b97997dcdae194692acc504 (patch) | |
tree | a8637472cc8672f582bb74d27ebc4cd348973596 | |
parent | 580acab20f9b9c4e5441b461859c00a99c1deee2 (diff) |
style: use 'dyn' for trait objects
And also add a `source` method on the `Error` impl.
And finally, permit the use of the deprecated `description` method,
since removing it would be a breaking change.
-rw-r--r-- | src/error.rs | 7 | ||||
-rw-r--r-- | src/lib.rs | 3 | ||||
-rw-r--r-- | src/tests/util.rs | 4 |
3 files changed, 9 insertions, 5 deletions
diff --git a/src/error.rs b/src/error.rs index ab9b17a..b084a58 100644 --- a/src/error.rs +++ b/src/error.rs @@ -203,6 +203,7 @@ impl Error { } impl error::Error for Error { + #[allow(deprecated)] fn description(&self) -> &str { match self.inner { ErrorInner::Io { ref err, .. } => err.description(), @@ -210,7 +211,11 @@ impl error::Error for Error { } } - fn cause(&self) -> Option<&error::Error> { + fn cause(&self) -> Option<&dyn error::Error> { + self.source() + } + + fn source(&self) -> Option<&(dyn error::Error + 'static)> { match self.inner { ErrorInner::Io { ref err, .. } => Some(err), ErrorInner::Loop { .. } => None, @@ -105,7 +105,6 @@ for entry in walker.filter_entry(|e| !is_hidden(e)) { #![deny(missing_docs)] #![allow(unknown_lints)] -#![allow(bare_trait_objects)] #[cfg(test)] #[macro_use] @@ -251,7 +250,7 @@ struct WalkDirOptions { min_depth: usize, max_depth: usize, sorter: Option<Box< - FnMut(&DirEntry,&DirEntry) -> Ordering + Send + Sync + 'static + dyn FnMut(&DirEntry,&DirEntry) -> Ordering + Send + Sync + 'static >>, contents_first: bool, same_file_system: bool, diff --git a/src/tests/util.rs b/src/tests/util.rs index d31a28d..ab977cd 100644 --- a/src/tests/util.rs +++ b/src/tests/util.rs @@ -11,12 +11,12 @@ use {DirEntry, Error}; #[macro_export] macro_rules! err { ($($tt:tt)*) => { - Box::<error::Error + Send + Sync>::from(format!($($tt)*)) + Box::<dyn error::Error + Send + Sync>::from(format!($($tt)*)) } } /// A convenient result type alias. -pub type Result<T> = result::Result<T, Box<error::Error + Send + Sync>>; +pub type Result<T> = result::Result<T, Box<dyn error::Error + Send + Sync>>; /// The result of running a recursive directory iterator on a single directory. #[derive(Debug)] |