Diffstat (limited to 'src/any.rs')
-rw-r--r--src/any.rs28
1 files changed, 12 insertions, 16 deletions
diff --git a/src/any.rs b/src/any.rs
index 0594e68..86c566a 100644
--- a/src/any.rs
+++ b/src/any.rs
@@ -16,31 +16,31 @@ pub use ref_any_unsized::*;
pub use static_wrapper::*;
pub use type_name_id::*;
-pub trait AnyTrait<'ctx> {
- fn upcast_by_id<'a, 'lt: 'a>(
+pub trait AnyTrait<'lt, 'ctx: 'lt>: 'lt {
+ fn upcast_by_id<'a>(
&'a self,
id: WithLtTypeId<'lt, 'ctx>,
) -> Option<RefAnyUnsized<'a, 'lt, 'ctx>>
where
- 'ctx: 'lt,
+ 'lt: 'a
{
let _id = id;
None
}
- fn upcast_by_id_mut<'a, 'lt: 'a>(
+ fn upcast_by_id_mut<'a>(
&'a mut self,
id: WithLtTypeId<'lt, 'ctx>,
) -> Option<MutAnyUnsized<'a, 'lt, 'ctx>>
where
- 'ctx: 'lt,
+ 'lt: 'a
{
let _id = id;
None
}
}
-impl<'lt, 'ctx: 'lt> dyn AnyTrait<'ctx> + 'lt {
+impl<'lt, 'ctx: 'lt> dyn AnyTrait<'lt, 'ctx> + 'lt {
#[track_caller]
pub fn upcast<'a, T: ?Sized + type_name::WithLt<'lt, 'ctx>>(&'a self) -> Option<&'a T> {
self.upcast_by_id(WithLtTypeId::of::<T>())
@@ -106,18 +106,16 @@ macro_rules! trait_by_id {
$this:ident,
$id:ident,
{
- type Impls<$lt:lifetime, $ctx:lifetime> = ($($trait:ty),* $(,)?);
-
- $($body:tt)*
+ type Impls = ($($trait:ty),* $(,)?);
}
} => {{
match $id {
$(
$id if $id == $crate::any::WithLtTypeId::of::<$trait>() => {
- Some($crate::any::RefAnyUnsized::new($this as &$trait))
+ return Some($crate::any::RefAnyUnsized::new($this as &$trait))
}
)*
- _ => { $($body)* }
+ _ => {}
}
}};
{
@@ -125,9 +123,7 @@ macro_rules! trait_by_id {
$this:ident,
$id:ident,
{
- type Impls<$lt:lifetime, $ctx:lifetime> = ($($trait:ty),* $(,)?);
-
- $($body:tt)*
+ type Impls = ($($trait:ty),* $(,)?);
}
} => {{
match $id {
@@ -136,10 +132,10 @@ macro_rules! trait_by_id {
eprintln!("a: {:?}\nb: {:?}", &$id, $crate::any::WithLtTypeId::of::<$trait>());
$id == $crate::any::WithLtTypeId::of::<$trait>()
}=> {
- Some($crate::any::MutAnyUnsized::new($this as &mut $trait))
+ return Some($crate::any::MutAnyUnsized::new($this as &mut $trait))
}
)*
- _ => { $($body)* }
+ _ => {}
}
}};
}