[−][src]Macro structural::declare_names_module
Declares a module with aliases for type-level idents,used to access fields.
Every one of these aliases are types and constants of the same name.
These aliases cannot be combined to pass to
GetFieldExt::fields
or GetFieldExt::fields_mut
.
When macros take in identifiers those must be the
literal identifiers for the fields(you can't pass aliases),
since they must check that the field names passed to the macro don't repeat
within the macro invocation.
Example
use structural::{declare_names_module,GetField,GetFieldExt}; declare_names_module!{ pub mod names{ _a, _b, _0, c, zero=0, one=1, two=2, e=10, g=abcd, // Used to access the `0`,`1`,and `2` fields // with the fields or fields_mut method. FirstThree=(0,1,2), h=(a,b,c), i=(0,3,5), j=(p), // The identifier can also be parenthesised k=("p"), // This is equivalent to the `j` alias } } fn assert_fields<T>(this:&T) where T:GetField<names::zero,Ty=i32>+ GetField<names::one,Ty=i32>+ GetField<names::two,Ty=i32> { assert_eq!( this.field_(names::zero), &2 ); assert_eq!( this.field_(names::one), &3 ); assert_eq!( this.field_(names::two), &5 ); assert_eq!( this.fields(names::FirstThree), (&2,&3,&5) ); } assert_fields(&(2,3,5)); assert_fields(&(2,3,5,8)); assert_fields(&(2,3,5,8,13)); assert_fields(&(2,3,5,8,13,21));