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>,{
pub get: G,
pub set: S,
/* 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.
Fields§
§get: GGetter closure: used by Kp::get for read-only access.
set: SSetter closure: used by Kp::get_mut for mutation.
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>
Trait Implementations§
Source§impl<R, V, Root, Value, MutRoot, MutValue, G, S> AccessorTrait<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> AccessorTrait<R, V, Root, Value, MutRoot, MutValue, G, S> for Kp<R, V, Root, Value, MutRoot, MutValue, G, S>
Source§fn get_optional(&self, root: Option<Root>) -> Option<Value>
fn get_optional(&self, root: Option<Root>) -> Option<Value>
Like get, but takes an optional root: returns None if root is None, otherwise the result of the getter.
Source§fn get_mut_optional(&self, root: Option<MutRoot>) -> Option<MutValue>
fn get_mut_optional(&self, root: Option<MutRoot>) -> Option<MutValue>
Like get_mut, but takes an optional root: returns None if root is None, otherwise the result of the setter.
Source§fn get_or_else<F>(&self, root: Root, f: F) -> Valuewhere
F: FnOnce() -> Value,
fn get_or_else<F>(&self, root: Root, f: F) -> Valuewhere
F: FnOnce() -> Value,
Returns the value if the keypath succeeds, otherwise calls f and returns its result.
Source§fn get_mut_or_else<F>(&self, root: MutRoot, f: F) -> MutValuewhere
F: FnOnce() -> MutValue,
fn get_mut_or_else<F>(&self, root: MutRoot, f: F) -> MutValuewhere
F: FnOnce() -> MutValue,
Returns the mutable value if the keypath succeeds, otherwise calls f and returns its result.
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,
.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>
Source§fn into_set(self) -> impl Fn(MutRoot) -> Option<MutValue>
fn into_set(self) -> impl Fn(MutRoot) -> Option<MutValue>
set fn is converting fn pointer to Fn closure
Source§fn into_get(self) -> impl Fn(Root) -> Option<Value>
fn into_get(self) -> impl Fn(Root) -> Option<Value>
get fn is converting fn pointer to Fn closure