Macro better_any::tid
source · [−]macro_rules! tid {
($struct: ident) => { ... };
($struct: ident < $lt: lifetime >) => { ... };
(impl <$lt:lifetime $(,$param:ident)*> $tr:ident<$lt2:lifetime> for $($struct: tt)+ ) => { ... };
(inner impl <$lt:lifetime $(,$param:ident)* static $( $static_param:ident)* > Tid<$lt2:lifetime> for $($struct: tt)+ ) => { ... };
(inner impl <$lt:lifetime $(,$param:ident)* static $( $static_param:ident)* > TidAble<$lt2:lifetime> for $($struct: tt)+ ) => { ... };
(inner impl <$lt:lifetime $(,$param:ident)* static $( $static_param:ident)* > $tr:ident<$lt2:lifetime> for $($struct: tt)+ ) => { ... };
(temp $(,$param:ident)* static $(,$static_param:ident)* impl <$lt:lifetime , $token:ident : 'static $($tail: tt)+ ) => { ... };
(temp $(,$param:ident)* static $(,$static_param:ident)* impl <$lt:lifetime , $token:ident $($tail: tt)+ ) => { ... };
(temp $(,$param:ident)* static $(,$static_param:ident)* impl <$lt:lifetime> $($tail: tt)+ ) => { ... };
( impl $($tail: tt)+) => { ... };
}
Expand description
Main safe implementation interface of related unsafe traits
It uses syntax of regular Rust impl
block but with parameters restricted enough to be sound.
In particular it is restricted to a single lifetime parameter in particular block.
and additional bounds must be in where clauses.
In trivial cases just type signature can be used.
struct S;
tid!(S);
struct F<'a>(&'a str);
tid!(F<'a>);
struct Bar<'x,'y,X,Y>(&'x str,&'y str,X,Y);
tid!{ impl<'b,X,Y> TidAble<'b> for Bar<'b,'b,X,Y> }
trait Test<'a>{}
tid!{ impl<'b> TidAble<'b> for dyn Test<'b> + 'b }
Implementation by default adds TidAble<'a>
bound on all generic parameters.
This behavior can be opted out by specifying 'static
bound on corresponding type parameter.
Note that due to decl macro limitations it must be specified directly on type parameter
and not in where clauses:
struct Test<'a,X:?Sized>(&'a str,Box<X>);
tid! { impl<'a,X:'static> Tid<'a> for Test<'a,X> where X:?Sized }