Macro frunk_core::field
[−]
[src]
macro_rules! field { (($($repeated: ty),*), $value: expr) => { ... }; (($($repeated: ty,)*), $value: expr) => { ... }; ($name_type: ty, $value: expr) => { ... }; ($name_type: ty, $value: expr, $name: expr) => { ... }; }
Used for creating a Field
There are 3 forms of this macro:
- Create an instance of the
Field
struct with a tuple name type and any given value. The runtime-retrievable static name field will be set to the the concatenation of the types passed in the tuple type used as the first argument.
let labelled = field![(n,a,m,e), "joe"]; assert_eq!(labelled.name, "name")Run
- Create an instance of the
Field
struct with a custom, non-tuple name type and a value. The runtime-retrievable static name field will be set to the stringified version of the type provided.
enum first_name {} let labelled = field![first_name, "Joe"]; assert_eq!(labelled.name, "first_name");Run
- Create an instance of the
Field
struct with any name type and value, and a custom name, passed as the last argument in the macro# #[macro_use] extern crate frunk_core; # use frunk_core::labelled::*; # use frunk_core::hlist::*; # fn main() { let labelled = field![(a,g,e), 30, "Age"]; assert_eq!(labelled.name, "Age"); # }