pub struct Kp<R, V, Root, Value, MutRoot, MutValue, G, S>where
Root: Borrow<R>,
MutRoot: BorrowMut<R>,
MutValue: BorrowMut<V>,
G: Fn(Root) -> Option<Value>,
S: Fn(MutRoot) -> Option<MutValue>,{ /* private fields */ }Expand description
AKp (AnyKeyPath) - Hides both Root and Value types Most flexible keypath type for heterogeneous collections Uses dynamic dispatch and type checking at runtime
§Mutation: get vs get_mut (setter path)
- get uses the
getclosure (getter):Fn(Root) -> Option<Value> - get_mut uses the
setclosure (setter):Fn(MutRoot) -> Option<MutValue>
When mutating through a Kp, the setter path is used—get_mut invokes the set closure,
not the get closure. The getter is for read-only access only.
Implementations§
Source§impl<'a, R, V> Kp<R, V, &'a R, &'a V, &'a mut R, &'a mut V, for<'b> fn(&'b R) -> Option<&'b V>, for<'b> fn(&'b mut R) -> Option<&'b mut V>>where
'a: 'static,
impl<'a, R, V> Kp<R, V, &'a R, &'a V, &'a mut R, &'a mut V, for<'b> fn(&'b R) -> Option<&'b V>, for<'b> fn(&'b mut R) -> Option<&'b mut V>>where
'a: 'static,
Sourcepub fn to_dynamic(self) -> KpDynamic<R, V>
pub fn to_dynamic(self) -> KpDynamic<R, V>
Converts this keypath (KpType) to KpDynamic for dynamic dispatch and storage.
Requires 'a: 'static so the boxed getter/setter closures can be 'static.
Source§impl<R, V> Kp<R, V, &'static R, &'static V, &'static mut R, &'static mut V, Box<dyn for<'b> Fn(&'b R) -> Option<&'b V> + Send + Sync>, Box<dyn for<'b> Fn(&'b mut R) -> Option<&'b mut V> + Send + Sync>>
impl<R, V> Kp<R, V, &'static R, &'static V, &'static mut R, &'static mut V, Box<dyn for<'b> Fn(&'b R) -> Option<&'b V> + Send + Sync>, Box<dyn for<'b> Fn(&'b mut R) -> Option<&'b mut V> + Send + Sync>>
Sourcepub fn from_closures<G, S>(get: G, set: S) -> Self
pub fn from_closures<G, S>(get: G, set: S) -> Self
Build a keypath from two closures (e.g. when they capture a variable like an index).
Same pattern as Kp::new in lock.rs; use this when the keypath captures variables.
Source§impl<R, V, Root, Value, MutRoot, MutValue, G, S> Kp<R, V, Root, Value, MutRoot, MutValue, G, S>
impl<R, V, Root, Value, MutRoot, MutValue, G, S> Kp<R, V, Root, Value, MutRoot, MutValue, G, S>
pub fn new(get: G, set: S) -> Self
pub fn get(&self, root: Root) -> Option<Value>
pub fn get_mut(&self, root: MutRoot) -> Option<MutValue>
pub fn then<SV, SubValue, MutSubValue, G2, S2>( self, next: Kp<V, SV, Value, SubValue, MutValue, MutSubValue, G2, S2>, ) -> Kp<R, SV, Root, SubValue, MutRoot, MutSubValue, impl Fn(Root) -> Option<SubValue>, impl Fn(MutRoot) -> Option<MutSubValue>>
Trait Implementations§
Source§impl<R, V, Root, Value, MutRoot, MutValue, G, S> ChainExt<R, V, Root, Value, MutRoot, MutValue> for Kp<R, V, Root, Value, MutRoot, MutValue, G, S>
impl<R, V, Root, Value, MutRoot, MutValue, G, S> ChainExt<R, V, Root, Value, MutRoot, MutValue> for Kp<R, V, Root, Value, MutRoot, MutValue, G, S>
Source§fn then_lock<Lock, Mid, V2, LockValue, MidValue, Value2, MutLock, MutMid, MutValue2, G1, S1, L, G2, S2>(
self,
lock_kp: LockKp<V, Lock, Mid, V2, Value, LockValue, MidValue, Value2, MutValue, MutLock, MutMid, MutValue2, G1, S1, L, G2, S2>,
) -> KpThenLockKp<R, V, V2, Root, Value, Value2, MutRoot, MutValue, MutValue2, Self, LockKp<V, Lock, Mid, V2, Value, LockValue, MidValue, Value2, MutValue, MutLock, MutMid, MutValue2, G1, S1, L, G2, S2>>where
V: 'static + Clone,
V2: 'static,
Value: Borrow<V>,
Value2: Borrow<V2>,
MutValue: BorrowMut<V>,
MutValue2: BorrowMut<V2>,
LockValue: Borrow<Lock>,
MidValue: Borrow<Mid>,
MutLock: BorrowMut<Lock>,
MutMid: BorrowMut<Mid>,
G1: Fn(Value) -> Option<LockValue>,
S1: Fn(MutValue) -> Option<MutLock>,
L: LockAccess<Lock, MidValue> + LockAccess<Lock, MutMid>,
G2: Fn(MidValue) -> Option<Value2>,
S2: Fn(MutMid) -> Option<MutValue2>,
fn then_lock<Lock, Mid, V2, LockValue, MidValue, Value2, MutLock, MutMid, MutValue2, G1, S1, L, G2, S2>(
self,
lock_kp: LockKp<V, Lock, Mid, V2, Value, LockValue, MidValue, Value2, MutValue, MutLock, MutMid, MutValue2, G1, S1, L, G2, S2>,
) -> KpThenLockKp<R, V, V2, Root, Value, Value2, MutRoot, MutValue, MutValue2, Self, LockKp<V, Lock, Mid, V2, Value, LockValue, MidValue, Value2, MutValue, MutLock, MutMid, MutValue2, G1, S1, L, G2, S2>>where
V: 'static + Clone,
V2: 'static,
Value: Borrow<V>,
Value2: Borrow<V2>,
MutValue: BorrowMut<V>,
MutValue2: BorrowMut<V2>,
LockValue: Borrow<Lock>,
MidValue: Borrow<Mid>,
MutLock: BorrowMut<Lock>,
MutMid: BorrowMut<Mid>,
G1: Fn(Value) -> Option<LockValue>,
S1: Fn(MutValue) -> Option<MutLock>,
L: LockAccess<Lock, MidValue> + LockAccess<Lock, MutMid>,
G2: Fn(MidValue) -> Option<Value2>,
S2: Fn(MutMid) -> Option<MutValue2>,
Source§fn then_async<AsyncKp>(
self,
async_kp: AsyncKp,
) -> KpThenAsyncKeyPath<R, V, <AsyncKp::Value as KeyPathValueTarget>::Target, Root, Value, AsyncKp::Value, MutRoot, MutValue, AsyncKp::MutValue, Self, AsyncKp>where
V: 'static,
Value: Borrow<V>,
MutValue: BorrowMut<V>,
AsyncKp: AsyncKeyPathLike<Value, MutValue>,
AsyncKp::Value: KeyPathValueTarget + Borrow<<AsyncKp::Value as KeyPathValueTarget>::Target>,
AsyncKp::MutValue: BorrowMut<<AsyncKp::Value as KeyPathValueTarget>::Target>,
<AsyncKp::Value as KeyPathValueTarget>::Target: 'static,
fn then_async<AsyncKp>(
self,
async_kp: AsyncKp,
) -> KpThenAsyncKeyPath<R, V, <AsyncKp::Value as KeyPathValueTarget>::Target, Root, Value, AsyncKp::Value, MutRoot, MutValue, AsyncKp::MutValue, Self, AsyncKp>where
V: 'static,
Value: Borrow<V>,
MutValue: BorrowMut<V>,
AsyncKp: AsyncKeyPathLike<Value, MutValue>,
AsyncKp::Value: KeyPathValueTarget + Borrow<<AsyncKp::Value as KeyPathValueTarget>::Target>,
AsyncKp::MutValue: BorrowMut<<AsyncKp::Value as KeyPathValueTarget>::Target>,
<AsyncKp::Value as KeyPathValueTarget>::Target: 'static,
Chain with an async keypath (e.g. crate::async_lock::AsyncLockKp). Use
.get(&root).await on the returned keypath.Source§impl<R: Clone, V: Clone, Root, Value: Clone, MutRoot, MutValue, G, S> Clone for Kp<R, V, Root, Value, MutRoot, MutValue, G, S>
impl<R: Clone, V: Clone, Root, Value: Clone, MutRoot, MutValue, G, S> Clone for Kp<R, V, Root, Value, MutRoot, MutValue, G, S>
Source§impl<R, V, Root, Value, MutRoot, MutValue, G, S> CoercionTrait<R, V, Root, Value, MutRoot, MutValue, G, S> for Kp<R, V, Root, Value, MutRoot, MutValue, G, S>
impl<R, V, Root, Value, MutRoot, MutValue, G, S> CoercionTrait<R, V, Root, Value, MutRoot, MutValue, G, S> for Kp<R, V, Root, Value, MutRoot, MutValue, G, S>
fn for_arc<'b>( &self, ) -> Kp<Arc<R>, V, Arc<R>, Value, Arc<R>, MutValue, impl Fn(Arc<R>) -> Option<Value>, impl Fn(Arc<R>) -> Option<MutValue>>
fn for_box<'a>( &self, ) -> Kp<Box<R>, V, Box<R>, Value, Box<R>, MutValue, impl Fn(Box<R>) -> Option<Value>, impl Fn(Box<R>) -> Option<MutValue>>
Source§impl<'a, R, V> From<Kp<R, V, &'a R, &'a V, &'a mut R, &'a mut V, for<'b> fn(&'b R) -> Option<&'b V>, for<'b> fn(&'b mut R) -> Option<&'b mut V>>> for KpDynamic<R, V>where
R: 'static,
V: 'static,
'a: 'static,
impl<'a, R, V> From<Kp<R, V, &'a R, &'a V, &'a mut R, &'a mut V, for<'b> fn(&'b R) -> Option<&'b V>, for<'b> fn(&'b mut R) -> Option<&'b mut V>>> for KpDynamic<R, V>where
R: 'static,
V: 'static,
'a: 'static,
Source§impl<R, V, Root, Value, MutRoot, MutValue, G, S> HOFTrait<R, V, Root, Value, MutRoot, MutValue, G, S> for Kp<R, V, Root, Value, MutRoot, MutValue, G, S>
impl<R, V, Root, Value, MutRoot, MutValue, G, S> HOFTrait<R, V, Root, Value, MutRoot, MutValue, G, S> for Kp<R, V, Root, Value, MutRoot, MutValue, G, S>
Source§fn map<MappedValue, F>(
&self,
mapper: F,
) -> Kp<R, MappedValue, Root, MappedValue, MutRoot, MappedValue, impl Fn(Root) -> Option<MappedValue> + '_, impl Fn(MutRoot) -> Option<MappedValue> + '_>
fn map<MappedValue, F>( &self, mapper: F, ) -> Kp<R, MappedValue, Root, MappedValue, MutRoot, MappedValue, impl Fn(Root) -> Option<MappedValue> + '_, impl Fn(MutRoot) -> Option<MappedValue> + '_>
Map the value through a transformation function.
Source§fn filter<F>(
&self,
predicate: F,
) -> Kp<R, V, Root, Value, MutRoot, MutValue, impl Fn(Root) -> Option<Value> + '_, impl Fn(MutRoot) -> Option<MutValue> + '_>
fn filter<F>( &self, predicate: F, ) -> Kp<R, V, Root, Value, MutRoot, MutValue, impl Fn(Root) -> Option<Value> + '_, impl Fn(MutRoot) -> Option<MutValue> + '_>
Filter the value based on a predicate.
Source§fn filter_map<MappedValue, F>(
&self,
mapper: F,
) -> Kp<R, MappedValue, Root, MappedValue, MutRoot, MappedValue, impl Fn(Root) -> Option<MappedValue> + '_, impl Fn(MutRoot) -> Option<MappedValue> + '_>
fn filter_map<MappedValue, F>( &self, mapper: F, ) -> Kp<R, MappedValue, Root, MappedValue, MutRoot, MappedValue, impl Fn(Root) -> Option<MappedValue> + '_, impl Fn(MutRoot) -> Option<MappedValue> + '_>
Map and flatten when mapper returns an Option.
Source§fn inspect<F>(
&self,
inspector: F,
) -> Kp<R, V, Root, Value, MutRoot, MutValue, impl Fn(Root) -> Option<Value> + '_, impl Fn(MutRoot) -> Option<MutValue> + '_>
fn inspect<F>( &self, inspector: F, ) -> Kp<R, V, Root, Value, MutRoot, MutValue, impl Fn(Root) -> Option<Value> + '_, impl Fn(MutRoot) -> Option<MutValue> + '_>
Apply a function for its side effects and return the value.
Source§fn flat_map<I, Item, F>(&self, mapper: F) -> impl Fn(Root) -> Vec<Item> + '_
fn flat_map<I, Item, F>(&self, mapper: F) -> impl Fn(Root) -> Vec<Item> + '_
Flat map - maps to an iterator and flattens.
Source§fn fold_value<Acc, F>(&self, init: Acc, folder: F) -> impl Fn(Root) -> Acc + '_
fn fold_value<Acc, F>(&self, init: Acc, folder: F) -> impl Fn(Root) -> Acc + '_
Fold/reduce the value using an accumulator function.
Source§fn any<F>(&self, predicate: F) -> impl Fn(Root) -> bool + '_
fn any<F>(&self, predicate: F) -> impl Fn(Root) -> bool + '_
Check if any element satisfies a predicate.
Source§fn all<F>(&self, predicate: F) -> impl Fn(Root) -> bool + '_
fn all<F>(&self, predicate: F) -> impl Fn(Root) -> bool + '_
Check if all elements satisfy a predicate.
Source§fn count_items<F>(&self, counter: F) -> impl Fn(Root) -> Option<usize> + '_
fn count_items<F>(&self, counter: F) -> impl Fn(Root) -> Option<usize> + '_
Count elements in a collection value.
Source§fn find_in<Item, F>(&self, finder: F) -> impl Fn(Root) -> Option<Item> + '_
fn find_in<Item, F>(&self, finder: F) -> impl Fn(Root) -> Option<Item> + '_
Find first element matching predicate in a collection value.
Source§fn take<Output, F>(
&self,
n: usize,
taker: F,
) -> impl Fn(Root) -> Option<Output> + '_
fn take<Output, F>( &self, n: usize, taker: F, ) -> impl Fn(Root) -> Option<Output> + '_
Take first N elements from a collection value.
Source§fn skip<Output, F>(
&self,
n: usize,
skipper: F,
) -> impl Fn(Root) -> Option<Output> + '_
fn skip<Output, F>( &self, n: usize, skipper: F, ) -> impl Fn(Root) -> Option<Output> + '_
Skip first N elements from a collection value.
Source§fn partition_value<Output, F>(
&self,
partitioner: F,
) -> impl Fn(Root) -> Option<Output> + '_
fn partition_value<Output, F>( &self, partitioner: F, ) -> impl Fn(Root) -> Option<Output> + '_
Partition a collection value into two groups based on predicate.
Source§fn min_value<Item, F>(&self, min_fn: F) -> impl Fn(Root) -> Option<Item> + '_
fn min_value<Item, F>(&self, min_fn: F) -> impl Fn(Root) -> Option<Item> + '_
Get min value from a collection.
Source§impl<R, V, Root, Value, MutRoot, MutValue, G, S> KpTrait<R, V, Root, Value, MutRoot, MutValue, G, S> for Kp<R, V, Root, Value, MutRoot, MutValue, G, S>
impl<R, V, Root, Value, MutRoot, MutValue, G, S> KpTrait<R, V, Root, Value, MutRoot, MutValue, G, S> for Kp<R, V, Root, Value, MutRoot, MutValue, G, S>
fn get(&self, root: Root) -> Option<Value>
fn get_mut(&self, root: MutRoot) -> Option<MutValue>
fn then<SV, SubValue, MutSubValue, G2, S2>( self, next: Kp<V, SV, Value, SubValue, MutValue, MutSubValue, G2, S2>, ) -> Kp<R, SV, Root, SubValue, MutRoot, MutSubValue, impl Fn(Root) -> Option<SubValue>, impl Fn(MutRoot) -> Option<MutSubValue>>
fn type_id_of_root() -> TypeIdwhere
R: 'static,
fn type_id_of_value() -> TypeIdwhere
V: 'static,
Source§impl<R, V, Root, Value, MutRoot, MutValue, G, S> SyncKeyPathLike<Root, Value, MutRoot, MutValue> for Kp<R, V, Root, Value, MutRoot, MutValue, G, S>
impl<R, V, Root, Value, MutRoot, MutValue, G, S> SyncKeyPathLike<Root, Value, MutRoot, MutValue> for Kp<R, V, Root, Value, MutRoot, MutValue, G, S>
impl<R, V, Root, Value, MutRoot, MutValue, G, S> Send for Kp<R, V, Root, Value, MutRoot, MutValue, G, S>
impl<R, V, Root, Value, MutRoot, MutValue, G, S> Sync for Kp<R, V, Root, Value, MutRoot, MutValue, G, S>
Auto Trait Implementations§
impl<R, V, Root, Value, MutRoot, MutValue, G, S> Freeze for Kp<R, V, Root, Value, MutRoot, MutValue, G, S>
impl<R, V, Root, Value, MutRoot, MutValue, G, S> RefUnwindSafe for Kp<R, V, Root, Value, MutRoot, MutValue, G, S>where
G: RefUnwindSafe,
S: RefUnwindSafe,
R: RefUnwindSafe,
V: RefUnwindSafe,
Root: RefUnwindSafe,
Value: RefUnwindSafe,
MutRoot: RefUnwindSafe,
MutValue: RefUnwindSafe,
impl<R, V, Root, Value, MutRoot, MutValue, G, S> Unpin for Kp<R, V, Root, Value, MutRoot, MutValue, G, S>
impl<R, V, Root, Value, MutRoot, MutValue, G, S> UnsafeUnpin for Kp<R, V, Root, Value, MutRoot, MutValue, G, S>where
G: UnsafeUnpin,
S: UnsafeUnpin,
impl<R, V, Root, Value, MutRoot, MutValue, G, S> UnwindSafe for Kp<R, V, Root, Value, MutRoot, MutValue, G, S>where
G: UnwindSafe,
S: UnwindSafe,
R: UnwindSafe,
V: UnwindSafe,
Root: UnwindSafe,
Value: UnwindSafe,
MutRoot: UnwindSafe,
MutValue: UnwindSafe,
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