pub struct KeyPath<Root: ?Sized, Value: 'static> { /* private fields */ }
Expand description
A non-fallible keypath.
Implementations§
Source§impl<Root, Value> KeyPath<Root, Value>
impl<Root, Value> KeyPath<Root, Value>
Sourcepub fn append<T>(&self, other: &KeyPath<Value, T>) -> KeyPath<Root, T>
pub fn append<T>(&self, other: &KeyPath<Value, T>) -> KeyPath<Root, T>
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§
Source§impl<Root: ?Sized, Value: 'static> AsRef<[PathComponent]> for KeyPath<Root, Value>
impl<Root: ?Sized, Value: 'static> AsRef<[PathComponent]> for KeyPath<Root, Value>
Source§fn as_ref(&self) -> &[PathComponent]
fn as_ref(&self) -> &[PathComponent]
Converts this type into a shared reference of the (usually inferred) input type.
Auto Trait Implementations§
impl<Root, Value> Freeze for KeyPath<Root, Value>where
Root: ?Sized,
impl<Root, Value> RefUnwindSafe for KeyPath<Root, Value>
impl<Root, Value> Send for KeyPath<Root, Value>
impl<Root, Value> Sync for KeyPath<Root, Value>
impl<Root, Value> Unpin for KeyPath<Root, Value>
impl<Root, Value> UnwindSafe for KeyPath<Root, Value>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more