Skip to main content

AKp

Struct AKp 

Source
pub struct AKp { /* private fields */ }

Implementations§

Source§

impl AKp

Source

pub fn new<'a, R, V>(keypath: KpType<'a, R, V>) -> Self
where R: Any + 'static, V: Any + 'static,

Create a new AKp from a KpType (the common reference-based keypath)

Source

pub fn from<'a, R, V>(keypath: KpType<'a, R, V>) -> Self
where R: Any + 'static, V: Any + 'static,

Create an AKp from a KpType (alias for new())

Source

pub fn get<'r>(&self, root: &'r dyn Any) -> Option<&'r dyn Any>

Get the value as a trait object (with root type checking)

Source

pub fn root_type_id(&self) -> TypeId

Get the TypeId of the Root type

Source

pub fn value_type_id(&self) -> TypeId

Get the TypeId of the Value type

Source

pub fn get_as<'a, Root: Any, Value: Any>( &self, root: &'a Root, ) -> Option<Option<&'a Value>>

Try to get the value with full type checking

Source

pub fn kind_name(&self) -> String

Get a human-readable name for the value type

Source

pub fn root_kind_name(&self) -> String

Get a human-readable name for the root type

Source

pub fn for_arc<Root>(&self) -> AKp
where Root: Any + 'static,

Adapt this keypath to work with Arc instead of Root

Source

pub fn for_box<Root>(&self) -> AKp
where Root: Any + 'static,

Adapt this keypath to work with Box instead of Root

Source

pub fn for_rc<Root>(&self) -> AKp
where Root: Any + 'static,

Adapt this keypath to work with Rc instead of Root

Source

pub fn for_option<Root>(&self) -> AKp
where Root: Any + 'static,

Adapt this keypath to work with Option instead of Root

Source

pub fn for_result<Root, E>(&self) -> AKp
where Root: Any + 'static, E: Any + 'static,

Adapt this keypath to work with Result<Root, E> instead of Root

Source

pub fn map<Root, OrigValue, MappedValue, F>(&self, mapper: F) -> AKp
where Root: Any + 'static, OrigValue: Any + 'static, MappedValue: Any + 'static, F: Fn(&OrigValue) -> MappedValue + 'static,

Map the value through a transformation function with type checking Both original and mapped values must implement Any

§Example
use rust_key_paths::{AKp, Kp, KpType};
struct User { name: String }
let user = User { name: "Alice".to_string() };
let name_kp = KpType::new(|u: &User| Some(&u.name), |_| None);
let name_akp = AKp::new(name_kp);
let len_akp = name_akp.map::<User, String, _, _>(|s| s.len());
Source

pub fn filter<Root, Value, F>(&self, predicate: F) -> AKp
where Root: Any + 'static, Value: Any + 'static, F: Fn(&Value) -> bool + 'static,

Filter the value based on a predicate with full type checking Returns None if types don’t match or predicate fails

§Example
use rust_key_paths::{AKp, Kp, KpType};
struct User { age: i32 }
let user = User { age: 30 };
let age_kp = KpType::new(|u: &User| Some(&u.age), |_| None);
let age_akp = AKp::new(age_kp);
let adult_akp = age_akp.filter::<User, i32, _>(|age| *age >= 18);

Auto Trait Implementations§

§

impl Freeze for AKp

§

impl !RefUnwindSafe for AKp

§

impl !Send for AKp

§

impl !Sync for AKp

§

impl Unpin for AKp

§

impl !UnwindSafe for AKp

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.