Macro frunk::field

source ·
macro_rules! field {
    (($($repeated: ty),*), $value: expr) => { ... };
    (($($repeated: ty,)*), $value: expr) => { ... };
    ($name_type: ty, $value: expr) => { ... };
    ($name_type: ty, $value: expr, $name: expr) => { ... };
}
Expand description

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.

Examples

use frunk::labelled::chars::*;
use frunk_core::field;
let labelled = field![(n,a,m,e), "joe"];
assert_eq!(labelled.name, "name");
assert_eq!(labelled.value, "joe")
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.
use frunk_core::field;
enum first_name {}
let labelled = field![first_name, "Joe"];
assert_eq!(labelled.name, "first_name");
assert_eq!(labelled.value, "Joe");
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
use frunk::labelled::chars::*;
use frunk_core::field;
// useful aliasing of our type-level string
type age = (a, g, e);
let labelled = field![age, 30, "Age"];
assert_eq!(labelled.name, "Age");
assert_eq!(labelled.value, 30);
Run