Diffstat (limited to 'src/any.rs')
| -rw-r--r-- | src/any.rs | 21 |
1 files changed, 18 insertions, 3 deletions
@@ -195,6 +195,8 @@ pub struct LtTypeId<'lt> { /// The type ID of the name type of the type. name_id: core::any::TypeId, + + name: &'static str, } impl<'lt> LtTypeId<'lt> { @@ -206,10 +208,17 @@ impl<'lt> LtTypeId<'lt> { LtTypeId { _marker: PhantomData, name_id: core::any::TypeId::of::<T::Name>(), + name: core::any::type_name::<T>(), } } } +impl<'lt> core::fmt::Display for LtTypeId<'lt> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + core::fmt::Display::fmt(self.name, f) + } +} + /// [`Any`][core::any::Any] with a lifetime generic `'lt`. /// /// This trait is implemented on all types that implement @@ -400,7 +409,7 @@ impl<'lt> dyn AnyTrait<'lt> + Send + '_ { #[macro_export] macro_rules! any_trait { { - impl[$a:lifetime, $lt:lifetime $($generic:tt)*] $name:ty = [$($protocol:ty),* $(,)?] $(where $($bound:tt)*)? + impl[$a:lifetime, $lt:lifetime $($generic:tt)*] $name:ty = [$($protocol:ty),* $(,)?] $(else $fallback:path)? $(where $($bound:tt)*)? } => { impl<$lt $($generic)*> $crate::any::AnyTrait<$lt> for $name $(where $($bound)*)? @@ -416,7 +425,10 @@ macro_rules! any_trait { match id { $(id if id == $crate::any::LtTypeId::of::<$protocol>() => ::core::option::Option::Some($crate::any::IndirectLtAny::<$a, $lt, _>::new::<$protocol>(self as _)),)* - _ => ::core::option::Option::None + _ => { + $($fallback(id);)? + ::core::option::Option::None + } } } @@ -431,7 +443,10 @@ macro_rules! any_trait { match id { $(id if id == $crate::any::LtTypeId::of::<$protocol>() => ::core::option::Option::Some($crate::any::IndirectLtAny::<$a, $lt, _>::new::<$protocol>(self as _)),)* - _ => ::core::option::Option::None + _ => { + $($fallback(id);)? + ::core::option::Option::None + } } } } |