From cacb7250229fabea1c9483b0d18f75a1f7e572c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98systems?= <> Date: Tue, 21 Jan 2020 14:43:16 +1000 Subject: [PATCH] remove unnecessary box cast --- actix-http/src/extensions.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/actix-http/src/extensions.rs b/actix-http/src/extensions.rs index 96860d28e..8d08a2599 100644 --- a/actix-http/src/extensions.rs +++ b/actix-http/src/extensions.rs @@ -35,26 +35,23 @@ impl Extensions { pub fn get(&self) -> Option<&T> { self.map .get(&TypeId::of::()) - .and_then(|boxed| (&**boxed as &(dyn Any + 'static)).downcast_ref()) + .and_then(|boxed| boxed.downcast_ref()) } /// Get a mutable reference to a type previously inserted on this `Extensions`. pub fn get_mut(&mut self) -> Option<&mut T> { self.map .get_mut(&TypeId::of::()) - .and_then(|boxed| (&mut **boxed as &mut (dyn Any + 'static)).downcast_mut()) + .and_then(|boxed| boxed.downcast_mut()) } /// Remove a type from this `Extensions`. /// /// If a extension of this type existed, it will be returned. pub fn remove(&mut self) -> Option { - self.map.remove(&TypeId::of::()).and_then(|boxed| { - (boxed as Box) - .downcast() - .ok() - .map(|boxed| *boxed) - }) + self.map + .remove(&TypeId::of::()) + .and_then(|boxed| boxed.downcast().ok().map(|boxed| *boxed)) } /// Clear the `Extensions` of all inserted extensions.