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 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.
Zip multiple keypaths on the same root and apply a closure to the tuple of values.
Returns Some(closure((v1, v2, ...))) when all keypaths succeed, else None.
EnumKp - A keypath for enum variants that supports both extraction and embedding
Leverages the existing Kp architecture where optionals are built-in via Option
The right shift operator >>. Note that because this trait is implemented
for all integer types with multiple right-hand-side types, Rust’s type
checker has special handling for _ >> _, setting the result type for
integer operations to the type of the left-hand-side operand. This means
that though a >> b and a.shr(b) are one and the same from an evaluation
standpoint, they are different when it comes to type inference.
Keypath for Option<RefCell<T>>: get returns Option<Ref<V>> so the caller holds the guard.
Use .get(root).as_ref().map(std::cell::Ref::deref) to get Option<&V> while the Ref is in scope.