Skip to content

Commit e4f013a

Browse files
committed
Use 'dyn' keyword with trait objects
1 parent 912534f commit e4f013a

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ matrix:
1414
- rustup target add wasm32-unknown-unknown
1515
- cargo build --target=wasm32-unknown-unknown
1616
# minimum rustc version
17-
- rust: 1.26.0
17+
- rust: 1.30.0
1818
script: cargo build
1919

2020
script:

src/error.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl Error {
4747
}
4848

4949
/// Return a reference to the lower level, inner error.
50-
pub fn get_ref(&self) -> &(error::Error + 'static) {
50+
pub fn get_ref(&self) -> &(dyn error::Error + 'static) {
5151
use self::ErrorKind::*;
5252

5353
match self.inner {
@@ -83,9 +83,8 @@ impl error::Error for Error {
8383

8484
// Return any available cause from the inner error. Note the inner error is
8585
// not itself the cause.
86-
#[allow(deprecated)]
87-
fn cause(&self) -> Option<&error::Error> {
88-
self.get_ref().cause()
86+
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
87+
self.get_ref().source()
8988
}
9089
}
9190

src/extensions.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::collections::HashMap;
33
use std::hash::{BuildHasherDefault, Hasher};
44
use std::fmt;
55

6-
type AnyMap = HashMap<TypeId, Box<Any + Send + Sync>, BuildHasherDefault<IdHasher>>;
6+
type AnyMap = HashMap<TypeId, Box<dyn Any + Send + Sync>, BuildHasherDefault<IdHasher>>;
77

88
// With TypeIds as keys, there's no need to hash them. They are already hashes
99
// themselves, coming from the compiler. The IdHasher just holds the u64 of
@@ -70,7 +70,7 @@ impl Extensions {
7070
.insert(TypeId::of::<T>(), Box::new(val))
7171
.and_then(|boxed| {
7272
//TODO: we can use unsafe and remove double checking the type id
73-
(boxed as Box<Any + 'static>)
73+
(boxed as Box<dyn Any + 'static>)
7474
.downcast()
7575
.ok()
7676
.map(|boxed| *boxed)
@@ -95,7 +95,7 @@ impl Extensions {
9595
.as_ref()
9696
.and_then(|map| map.get(&TypeId::of::<T>()))
9797
//TODO: we can use unsafe and remove double checking the type id
98-
.and_then(|boxed| (&**boxed as &(Any + 'static)).downcast_ref())
98+
.and_then(|boxed| (&**boxed as &(dyn Any + 'static)).downcast_ref())
9999
}
100100

101101
/// Get a mutable reference to a type previously inserted on this `Extensions`.
@@ -116,7 +116,7 @@ impl Extensions {
116116
.as_mut()
117117
.and_then(|map| map.get_mut(&TypeId::of::<T>()))
118118
//TODO: we can use unsafe and remove double checking the type id
119-
.and_then(|boxed| (&mut **boxed as &mut (Any + 'static)).downcast_mut())
119+
.and_then(|boxed| (&mut **boxed as &mut (dyn Any + 'static)).downcast_mut())
120120
}
121121

122122

@@ -140,7 +140,7 @@ impl Extensions {
140140
.and_then(|map| map.remove(&TypeId::of::<T>()))
141141
.and_then(|boxed| {
142142
//TODO: we can use unsafe and remove double checking the type id
143-
(boxed as Box<Any + 'static>)
143+
(boxed as Box<dyn Any + 'static>)
144144
.downcast()
145145
.ok()
146146
.map(|boxed| *boxed)

0 commit comments

Comments
 (0)