Struct keypath::KeyPath[][src]

pub struct KeyPath<Root: ?Sized, Value: 'static> { /* fields omitted */ }
Expand description

A non-fallible keypath.

Implementations

Create a new KeyPath by combining two routes.

The final type of the first route must be the first type of the second route; assuming both paths were created with the keypath! macro, the resulting path must be valid.

Examples

use keypath::{Keyable, KeyPath, keypath};

#[derive(Keyable)]
struct Person {
    name: String,
    friends: Vec<String>,
    size: Size,
}

#[derive(Keyable)]
struct Size {
    big: bool,
    heft: u8,
}

let mut person = Person {
    name: "coco".into(),
    friends: vec!["eli".into(), "nico".into(), "yaya".into()],
    size: Size { big: false, heft: 45 }
};

let size = keypath!(Person.size);
let heft = keypath!(Size.heft);
let combined = size.append(&heft);

assert_eq!(person[&combined], 45);

Trait Implementations

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.