Skip to main content

Crate rust_key_paths

Crate rust_key_paths 

Source

Re-exports§

pub use lock::ArcMutexAccess;
pub use lock::ArcRwLockAccess;
pub use lock::LockAccess;
pub use lock::LockKp;
pub use lock::LockKpType;
pub use lock::RcRefCellAccess;
pub use lock::StdMutexAccess;
pub use lock::StdRwLockAccess;

Modules§

async_lock
Async Lock Keypath Module
lock
Lock Keypath Module

Macros§

get_or
Get value through a keypath or a default reference when the path returns None. Use with KpType: get_or!(User::name(), &user, &default) where default is &T (same type as the path value). Returns &T. Path syntax: get_or!(&user => User.name, &default).
get_or_else
Get value through a keypath, or compute an owned fallback when the path returns None. Use with KpType: get_or_else!(User::name(), &user, || "default".to_string()). Returns T (owned). The keypath’s value type must be Clone. The closure is only called when the path is None. Path syntax: get_or_else!(&user => (User.name), || "default".to_string()) — path in parentheses.
keypath
Build a keypath from Type.field segments. Use with types that have keypath accessors (e.g. #[derive(Kp)] from key-paths-derive).

Structs§

AKp
EnumKp
EnumKp - A keypath for enum variants that supports both extraction and embedding Leverages the existing Kp architecture where optionals are built-in via Option
Kp
AKp (AnyKeyPath) - Hides both Root and Value types Most flexible keypath type for heterogeneous collections Uses dynamic dispatch and type checking at runtime
PKp

Traits§

KeyPathValueTarget
Used so that then_async can infer V2 from AsyncKp::Value without ambiguity (e.g. &i32 has both Borrow<i32> and Borrow<&i32>; this picks the referent). Implemented only for reference types so there is no overlap with the blanket impl.

Functions§

enum_err
Extract from Result<T, E> - Err variant
enum_ok
Extract from Result<T, E> - Ok variant
enum_some
Extract from Option - Some variant
enum_variant
Create an enum keypath with both extraction and embedding for a specific variant
kp_arc
Create a keypath for unwrapping Arc -> T (read-only)
kp_box
Create a keypath for unwrapping Box -> T
kp_rc
Create a keypath for unwrapping Rc -> T (read-only)
variant_of
Create an enum keypath for a specific variant with type inference
zip_kps
Zip two keypaths together to create a tuple Works only with KpType (reference-based keypaths)

Type Aliases§

EnumKpType
KpArc
KpBox
KpComposed
KpDynamic
KpType