From: Chris Morgan Date: Tue, 25 Jan 2022 13:57:40 +0000 (+1100) Subject: Narrow an unsafe block to the minimum X-Git-Tag: 1.0.0-beta.2~6 X-Git-Url: https://git.chrismorgan.info/anymap/commitdiff_plain/ff0fd8d0cf6d6bbd91fd152efab049235e292fbc?hp=0316c0faea94309c896f63bd1986107bf533a079 Narrow an unsafe block to the minimum This was necessary in the days of the raw module, when inserting to the raw map was the unsafe operation rather than getting mutable access to the raw map, to which I have changed it now. --- diff --git a/src/lib.rs b/src/lib.rs index 79a4561..1742701 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -221,10 +221,8 @@ impl Map { /// Otherwise, `None` is returned. #[inline] pub fn insert>(&mut self, value: T) -> Option { - unsafe { - self.raw.insert(TypeId::of::(), value.into_box()) - .map(|any| *any.downcast_unchecked::()) - } + self.raw.insert(TypeId::of::(), value.into_box()) + .map(|any| unsafe { *any.downcast_unchecked::() }) } // rustc 1.60.0-nightly has another method try_insert that would be nice to add when stable.