pub struct AKp { /* private fields */ }Implementations§
Source§impl AKp
impl AKp
Sourcepub fn new<'a, R, V>(keypath: KpType<'a, R, V>) -> Self
pub fn new<'a, R, V>(keypath: KpType<'a, R, V>) -> Self
Create a new AKp from a KpType (the common reference-based keypath)
Sourcepub fn from<'a, R, V>(keypath: KpType<'a, R, V>) -> Self
pub fn from<'a, R, V>(keypath: KpType<'a, R, V>) -> Self
Create an AKp from a KpType (alias for new())
Sourcepub fn get<'r>(&self, root: &'r dyn Any) -> Option<&'r dyn Any>
pub fn get<'r>(&self, root: &'r dyn Any) -> Option<&'r dyn Any>
Get the value as a trait object (with root type checking)
Sourcepub fn root_type_id(&self) -> TypeId
pub fn root_type_id(&self) -> TypeId
Get the TypeId of the Root type
Sourcepub fn value_type_id(&self) -> TypeId
pub fn value_type_id(&self) -> TypeId
Get the TypeId of the Value type
Sourcepub fn get_as<'a, Root: Any, Value: Any>(
&self,
root: &'a Root,
) -> Option<Option<&'a Value>>
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
Sourcepub fn root_kind_name(&self) -> String
pub fn root_kind_name(&self) -> String
Get a human-readable name for the root type
Sourcepub fn for_arc<Root>(&self) -> AKpwhere
Root: Any + 'static,
pub fn for_arc<Root>(&self) -> AKpwhere
Root: Any + 'static,
Adapt this keypath to work with Arc
Sourcepub fn for_box<Root>(&self) -> AKpwhere
Root: Any + 'static,
pub fn for_box<Root>(&self) -> AKpwhere
Root: Any + 'static,
Adapt this keypath to work with Box
Sourcepub fn for_rc<Root>(&self) -> AKpwhere
Root: Any + 'static,
pub fn for_rc<Root>(&self) -> AKpwhere
Root: Any + 'static,
Adapt this keypath to work with Rc
Sourcepub fn for_option<Root>(&self) -> AKpwhere
Root: Any + 'static,
pub fn for_option<Root>(&self) -> AKpwhere
Root: Any + 'static,
Adapt this keypath to work with Option
Sourcepub fn for_result<Root, E>(&self) -> AKp
pub fn for_result<Root, E>(&self) -> AKp
Adapt this keypath to work with Result<Root, E> instead of Root
Sourcepub fn map<Root, OrigValue, MappedValue, F>(&self, mapper: F) -> AKpwhere
Root: Any + 'static,
OrigValue: Any + 'static,
MappedValue: Any + 'static,
F: Fn(&OrigValue) -> MappedValue + 'static,
pub fn map<Root, OrigValue, MappedValue, F>(&self, mapper: F) -> AKpwhere
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());Sourcepub fn filter<Root, Value, F>(&self, predicate: F) -> AKp
pub fn filter<Root, Value, F>(&self, predicate: F) -> AKp
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);