[−][src]Macro structural::FP
Constructs a FieldPath(Set) for use as a generic parameter.
Improved macro
To get an improved version of this macro which can use the same syntax
as the fp
macro,you can do any of:
-
Use Rust 1.40 or greater
-
Use the
nightly_better_macros
cargo feature. -
Use the
better_macros
cargo feature.
Examples
This demonstrates how one can bound types by the accessor traits in a where clause.
use structural::{GetField,GetFieldExt,fp,FP}; fn greet_entity<This,S>(entity:&This) where // From 1.40 onwards you can also write `FP!(name)`. // // Before 1.40, you can use `field_path_aliases!{ name }` before this function, // then write this as `This:GetField<name,Ty=S>` This:GetField<FP!(n a m e),Ty=S>, S:AsRef<str>, { println!("Hello, {}!",entity.field_(fp!(name)).as_ref() ); }
Example
This demonstrates the improved version of this macro.
ⓘThis example is not tested
use structural::{GetField,GetFieldExt,fp,FP}; fn greet_entity<This,S>(entity:&This) where This:GetField<FP!(name),Ty=S>, S:AsRef<str>, { println!("Hello, {}!",entity.field_(fp!(name)).as_ref() ); } type NumericIdent=FP!(0); type StringyIdent=FP!(huh);