From 64367023b1a8675f8b97997dcdae194692acc504 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Sat, 11 Jan 2020 12:27:20 -0500 Subject: 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. --- src/error.rs | 7 ++++++- src/lib.rs | 3 +-- 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, diff --git a/src/lib.rs b/src/lib.rs index 51778e4..6a7bd63 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 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::::from(format!($($tt)*)) + Box::::from(format!($($tt)*)) } } /// A convenient result type alias. -pub type Result = result::Result>; +pub type Result = result::Result>; /// The result of running a recursive directory iterator on a single directory. #[derive(Debug)] -- cgit v1.2.3