Struct KeyPath

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

A non-fallible keypath.

Implementations§

Source§

impl<Root, Value> KeyPath<Root, Value>

Source

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>

Source§

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>
where Value: RefUnwindSafe, Root: RefUnwindSafe + ?Sized,

§

impl<Root, Value> Send for KeyPath<Root, Value>
where Value: Send, Root: Send + ?Sized,

§

impl<Root, Value> Sync for KeyPath<Root, Value>
where Value: Sync, Root: Sync + ?Sized,

§

impl<Root, Value> Unpin for KeyPath<Root, Value>
where Value: Unpin, Root: Unpin + ?Sized,

§

impl<Root, Value> UnwindSafe for KeyPath<Root, Value>
where Value: UnwindSafe, Root: UnwindSafe + ?Sized,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.