keypath 0.2.0

Derivable, type-safe Swift-style keypaths.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use keypath::{keypath, Keyable};

#[derive(Keyable)]
pub struct DemoPerson(String, f64, Size, (f32, f32));

#[derive(Keyable)]
pub struct Size(f64, f64);

#[test]
fn keypath() {
    let mut person = DemoPerson("coco".to_string(), 42.0, Size(1.0, 5.0), (2.0, 4.0));

    let path = keypath!(DemoPerson.2 .0);
    assert_eq!(person[&path], 1.0);
    person[&path] = 15.0;
    assert_eq!(person.2 .0, 15.0);
}