macro_rules! tstr_aliases {
(
$(#[$attr:meta])*
$vis:vis mod $mod_name:ident{
$($mod_contents:tt)*
}
) => { ... };
(
$($macro_params:tt)*
) => { ... };
}Expand description
Declares type aliases for TStr<_>(type-level string).
§Variants
§Inline
Where the aliases are declared at the scope that the macro is invoked.
This variant cannot be invoked within functions.
Small example:
use structural::tstr_aliases;
tstr_aliases!{
a, // Declares a type alias `a` with the "a" TStr.
b="b", // Declares a type alias `b` with the "b" TStr.
}§Module
Where the aliases are declared inside a nested module.
This variant can be invoked within functions.
Small example:
use structural::tstr_aliases;
fn hello(){
tstr_aliases!{
mod hello{
a,
b="b",
}
}
}§Example
Writing a function that takes a ::Foo.bar field.
You can use tstr_aliases or TS to manually declare
variant field accessor trait bounds.
use structural::{
field::GetVariantField,
StructuralExt,Structural,
tstr_aliases,fp,
};
tstr_aliases!{
mod strs{
Foo,
bar,
}
}
fn takes_enum( enum_:&dyn GetVariantField< strs::Foo, strs::bar, Ty= u32 > )-> Option<u32> {
enum_.field_(fp!(::Foo.bar)).cloned()
}
#[derive(Structural)]
enum Baz{
Foo{ bar:u32 },
Bar,
}
fn main(){
assert_eq!( takes_enum(&Baz::Foo{bar:0}), Some(0) );
assert_eq!( takes_enum(&Baz::Foo{bar:5}), Some(5) );
assert_eq!( takes_enum(&Baz::Bar), None );
}