Skip to main content

AccessorTrait

Trait AccessorTrait 

Source
pub trait AccessorTrait<Root, Value, MutRoot, MutValue>: Readable<Root, Value> + Writable<MutRoot, MutValue> {
    // Provided methods
    fn get_optional(&self, root: Option<Root>) -> Option<Value> { ... }
    fn get_mut_optional(&self, root: Option<MutRoot>) -> Option<MutValue> { ... }
    fn get_or_else<F>(&self, root: Root, f: F) -> Value
       where F: FnOnce() -> Value { ... }
    fn get_mut_or_else<F>(&self, root: MutRoot, f: F) -> MutValue
       where F: FnOnce() -> MutValue { ... }
}
Expand description

Optional-root and fallback helpers built on Readable / Writable.

Provided Methods§

Source

fn get_optional(&self, root: Option<Root>) -> Option<Value>

Like Readable::get, but takes an optional root.

Source

fn get_mut_optional(&self, root: Option<MutRoot>) -> Option<MutValue>

Like Writable::set, but takes an optional root.

Source

fn get_or_else<F>(&self, root: Root, f: F) -> Value
where F: FnOnce() -> Value,

Returns the value if the keypath succeeds, otherwise calls f.

Source

fn get_mut_or_else<F>(&self, root: MutRoot, f: F) -> MutValue
where F: FnOnce() -> MutValue,

Returns the mutable value if the keypath succeeds, otherwise calls f.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<R, V, Root, Value, MutRoot, MutValue, G, S> AccessorTrait<Root, Value, MutRoot, MutValue> for Kp<R, V, Root, Value, MutRoot, MutValue, G, S>
where Root: Borrow<R>, Value: Borrow<V>, MutRoot: BorrowMut<R>, MutValue: BorrowMut<V>, G: Fn(Root) -> Option<Value>, S: Fn(MutRoot) -> Option<MutValue>,