From ae9a975576620a32c719339fa57d4f7e5c344c93 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sun, 5 Apr 2020 09:56:52 +0800 Subject: [PATCH] Make downcast_ref, downcast_mut and is public. --- src/any.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/any.rs b/src/any.rs index 814e369a..7e7494e8 100644 --- a/src/any.rs +++ b/src/any.rs @@ -92,15 +92,13 @@ impl Any for T { impl Variant { /// Is this `Variant` a specific type? - pub(crate) fn is(&self) -> bool { - let t = TypeId::of::(); - let boxed = ::type_id(self); - - t == boxed + pub fn is(&self) -> bool { + TypeId::of::() == ::type_id(self) } /// Get a reference of a specific type to the `Variant`. - pub(crate) fn downcast_ref(&self) -> Option<&T> { + /// Returns `None` if the cast fails. + pub fn downcast_ref(&self) -> Option<&T> { if self.is::() { unsafe { Some(&*(self as *const Variant as *const T)) } } else { @@ -109,7 +107,8 @@ impl Variant { } /// Get a mutable reference of a specific type to the `Variant`. - pub(crate) fn downcast_mut(&mut self) -> Option<&mut T> { + /// Returns `None` if the cast fails. + pub fn downcast_mut(&mut self) -> Option<&mut T> { if self.is::() { unsafe { Some(&mut *(self as *mut Variant as *mut T)) } } else {