//! This library provides some utility traits to make working with [`Any`] smoother. //! This crate contains similar functionality to the `downcast` crate, but simpler, use std::any::{Any, TypeId};
/// This trait is an extension trait to [`Any`], and adds methods to retrieve a `&dyn Any` pubtraitAsAny: Any { fnas_any(&self) -> &dyn Any;
fnas_any_mut(&mutself) -> &mutdyn Any;
/// Gets the type name of `self` fntype_name(&self) -> TypeId; }
impl<T: 'static> AsAny forT { #[inline(always)] fnas_any(&self) -> &dyn Any { self }
#[inline(always)] fnas_any_mut(&mutself) -> &mutdyn Any { self }
/// This is a shim around `AaAny` to avoid some boilerplate code. /// It is a separate trait because it is also implemented /// on runtime polymorphic traits (which are `!Sized`). pubtraitDowncast: AsAny { /// Returns `true` if the boxed type is the same as `T`. /// /// Forward to the method defined on the type `Any`. #[inline(always)] fnis<T>(&self) ->bool where T: AsAny, { self.as_any().is::<T>() }
/// Forward to the method defined on the type `Any`. #[inline(always)] fndowncast_ref<T>(&self) ->Option<&T> where T: AsAny, { self.as_any().downcast_ref() }
/// Forward to the method defined on the type `Any`. #[inline(always)] fndowncast_mut<T>(&mutself) ->Option<&mut T> where T: AsAny, { self.as_any_mut().downcast_mut() } }