From 01885f995456d439f3876460518961ae76afa190 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Sun, 5 Dec 2021 04:49:52 +0000 Subject: [PATCH] inline unsafe --- actix-http/src/extensions.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/actix-http/src/extensions.rs b/actix-http/src/extensions.rs index 1c35cb59..1d7b84fc 100644 --- a/actix-http/src/extensions.rs +++ b/actix-http/src/extensions.rs @@ -195,12 +195,6 @@ trait UncheckedAnyExt { impl UncheckedAnyExt for dyn CloneAny {} -fn downcast_cloneable(boxed: Box) -> T { - // Safety: - // Box is owned and `T` is known to be true type from map containing TypeId as key. - *unsafe { UncheckedAnyExt::downcast_unchecked::(boxed) } -} - /// A type map for `on_connect` extensions. /// /// All entries into this map must be owned types and implement `Clone` trait. @@ -221,6 +215,7 @@ impl CloneableExtensions { /// /// If an item of this type was already stored, it will be replaced and returned. /// + /// # Examples /// ``` /// # use actix_http::Extensions; /// let mut map = Extensions::new(); @@ -232,7 +227,11 @@ impl CloneableExtensions { pub fn insert(&mut self, val: T) -> Option { self.map .insert(TypeId::of::(), Box::new(val)) - .and_then(downcast_cloneable) + .map(|boxed| { + // Safety: + // Box is owned and `T` is known to be true type from map. + *unsafe { UncheckedAnyExt::downcast_unchecked::(boxed) } + }) } #[cfg(test)]