Module frunk::path

source ·
Expand description

Holds models, traits, and logic for generic traversal of models

#[macro_use] extern crate frunk;
#[macro_use] extern crate frunk_core; // required when using custom derives
#[derive(LabelledGeneric)]
struct Address<'a> {
    name: &'a str,
}

#[derive(LabelledGeneric)]
struct User<'a> {
    name: &'a str,
    address: Address<'a>,
}

let u = User {
  name: "Joe",
  address: Address { name: "blue pond" },
};

let name_path = path!(name);

{
let traversed_name = name_path.get(&u);
assert_eq!(*traversed_name, "Joe");
}

// You can also **add** paths together
let address_path = path!(address);
let address_name_path = address_path + name_path;

let traversed_address_name = address_name_path.get(u);
assert_eq!(traversed_address_name, "blue pond");
Run

Structs

Traits

Trait for traversing based on Path