Skip to main content

AccessorTrait

Trait AccessorTrait 

Source
pub trait AccessorTrait<R, V, Root, Value, MutRoot, MutValue, G, S> {
    // Required 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;
}

Required Methods§

Source

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>

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) -> Value
where 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) -> MutValue
where F: FnOnce() -> MutValue,

Returns the mutable value if the keypath succeeds, otherwise calls f and returns its result.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

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>
where Root: Borrow<R>, Value: Borrow<V>, MutRoot: BorrowMut<R>, MutValue: BorrowMut<V>, G: Fn(Root) -> Option<Value>, S: Fn(MutRoot) -> Option<MutValue>,