macro_rules! alias {
($( $(#[doc = $doc:expr])* $vis:vis $ident:ident $body:tt ),* $(,)?) => { ... };
(@struct $vis:vis $ident:ident { $($tt:tt)* }) => { ... };
(@struct $vis:vis $ident:ident ( $($tt:tt)* )) => { ... };
}
Expand description
Assigns a token stream to an identifier.
This is done by generating a unit struct that implements ToTokens
.
The struct can be then interpolated in quote!
invocations or have its ToTokens
methods called directly.
Visibility and doc comments are also passed through to the struct.
ยงUsage
use quote_alias::alias;
use quote::quote;
alias! {
/// `Foo` from `my_crate::foo`
pub Foo(my_crate::foo::Foo),
this_and_that {
my_crate::this();
my_crate::that();
},
}
// same as: quote! { my_crate::foo::Foo::new() };
quote! { #Foo::new() };
// same as: quote! {
// my_crate::this();
// my_crate::that();
// };
quote! { #this_and_that };