OptionalKeyPath

Struct OptionalKeyPath 

Source
pub struct OptionalKeyPath<Root, Value, F>
where F: for<'r> Fn(&'r Root) -> Option<&'r Value>,
{ /* private fields */ }

Implementations§

Source§

impl<Root, Value, F> OptionalKeyPath<Root, Value, F>
where F: for<'r> Fn(&'r Root) -> Option<&'r Value>,

Source

pub fn new(getter: F) -> Self

Source

pub fn get<'r>(&self, root: &'r Root) -> Option<&'r Value>

Source

pub fn then<SubValue, G>( self, next: OptionalKeyPath<Value, SubValue, G>, ) -> OptionalKeyPath<Root, SubValue, impl for<'r> Fn(&'r Root) -> Option<&'r SubValue>>
where G: for<'r> Fn(&'r Value) -> Option<&'r SubValue> + 'static, F: 'static, Value: 'static,

Source

pub fn for_box<Target>( self, ) -> OptionalKeyPath<Root, Target, impl for<'r> Fn(&'r Root) -> Option<&'r Target> + 'static>
where Value: Deref<Target = Target> + 'static, F: 'static,

Source

pub fn for_arc<Target>( self, ) -> OptionalKeyPath<Root, Target, impl for<'r> Fn(&'r Root) -> Option<&'r Target> + 'static>
where Value: Deref<Target = Target> + 'static, F: 'static,

Source

pub fn for_rc<Target>( self, ) -> OptionalKeyPath<Root, Target, impl for<'r> Fn(&'r Root) -> Option<&'r Target> + 'static>
where Value: Deref<Target = Target> + 'static, F: 'static,

Source

pub fn for_option( self, ) -> OptionalKeyPath<Option<Root>, Value, impl for<'r> Fn(&'r Option<Root>) -> Option<&'r Value> + 'static>
where F: 'static, Root: 'static, Value: 'static,

Adapt this keypath to work with Option instead of Root This unwraps the Option and applies the keypath to the inner value

Source

pub fn for_result<E>( self, ) -> OptionalKeyPath<Result<Root, E>, Value, impl for<'r> Fn(&'r Result<Root, E>) -> Option<&'r Value> + 'static>
where F: 'static, Root: 'static, Value: 'static, E: 'static,

Adapt this keypath to work with Result<Root, E> instead of Root This unwraps the Result and applies the keypath to the Ok value

Source

pub fn for_arc_root( self, ) -> OptionalKeyPath<Arc<Root>, Value, impl for<'r> Fn(&'r Arc<Root>) -> Option<&'r Value> + 'static>
where Value: Sized + 'static, F: 'static, Root: 'static,

Source

pub fn for_rc_root( self, ) -> OptionalKeyPath<Rc<Root>, Value, impl for<'r> Fn(&'r Rc<Root>) -> Option<&'r Value> + 'static>
where Value: Sized + 'static, F: 'static, Root: 'static,

Source

pub fn with_option<Callback, R>( &self, option: &Option<Root>, f: Callback, ) -> Option<R>
where F: Clone, Callback: FnOnce(&Value) -> R,

Execute a closure with a reference to the value inside an Option

Source

pub fn with_mutex<Callback, R>( &self, mutex: &Mutex<Root>, f: Callback, ) -> Option<R>
where F: Clone, Callback: FnOnce(&Value) -> R,

Execute a closure with a reference to the value inside a Mutex

Source

pub fn with_rwlock<Callback, R>( &self, rwlock: &RwLock<Root>, f: Callback, ) -> Option<R>
where F: Clone, Callback: FnOnce(&Value) -> R,

Execute a closure with a reference to the value inside an RwLock

Source

pub fn with_arc_rwlock<Callback, R>( &self, arc_rwlock: &Arc<RwLock<Root>>, f: Callback, ) -> Option<R>
where F: Clone, Callback: FnOnce(&Value) -> R,

Execute a closure with a reference to the value inside an Arc<RwLock>

Source

pub fn with_arc_rwlock_direct<Callback, R>( &self, arc_rwlock: &Arc<RwLock<Root>>, f: Callback, ) -> Option<R>
where Callback: FnOnce(&Value) -> R,

Execute a closure with a reference to the value inside an Arc<RwLock> This is a convenience method that works directly with Arc<RwLock> Unlike with_arc_rwlock, this doesn’t require F: Clone

Source

pub fn with_arc_mutex<Callback, R>( &self, arc_mutex: &Arc<Mutex<Root>>, f: Callback, ) -> Option<R>
where F: Clone, Callback: FnOnce(&Value) -> R,

Execute a closure with a reference to the value inside an Arc<Mutex>

Source§

impl<Root, Value, F> OptionalKeyPath<Root, Value, F>
where F: for<'r> Fn(&'r Root) -> Option<&'r Value> + 'static, Root: Any + 'static, Value: Any + 'static,

Source

pub fn to_partial(self) -> PartialOptionalKeyPath<Root>

Convert to PartialOptionalKeyPath (hides Value type)

Source

pub fn to_any(self) -> AnyKeyPath

Convert to AnyKeyPath (hides both Root and Value types)

Source

pub fn to(self) -> PartialOptionalKeyPath<Root>

Convert to PartialOptionalKeyPath (alias for to_partial())

Trait Implementations§

Source§

impl<Root: Clone, Value: Clone, F> Clone for OptionalKeyPath<Root, Value, F>
where F: for<'r> Fn(&'r Root) -> Option<&'r Value> + Clone,

Source§

fn clone(&self) -> OptionalKeyPath<Root, Value, F>

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Root, Value, F> WithContainer<Root, Value> for OptionalKeyPath<Root, Value, F>
where F: for<'r> Fn(&'r Root) -> Option<&'r Value> + Clone,

Source§

fn with_arc<Callback, R>(&self, arc: &Arc<Root>, f: Callback) -> R
where Callback: FnOnce(&Value) -> R,

Execute a closure with a reference to the value inside an Arc
Source§

fn with_box<Callback, R>(&self, boxed: &Box<Root>, f: Callback) -> R
where Callback: FnOnce(&Value) -> R,

Execute a closure with a reference to the value inside a Box
Source§

fn with_box_mut<Callback, R>(&self, _boxed: &mut Box<Root>, _f: Callback) -> R
where Callback: FnOnce(&mut Value) -> R,

Execute a closure with a mutable reference to the value inside a Box
Source§

fn with_rc<Callback, R>(&self, rc: &Rc<Root>, f: Callback) -> R
where Callback: FnOnce(&Value) -> R,

Execute a closure with a reference to the value inside an Rc
Source§

fn with_result<Callback, R, E>( &self, result: &Result<Root, E>, f: Callback, ) -> Option<R>
where Callback: FnOnce(&Value) -> R,

Execute a closure with a reference to the value inside a Result
Source§

fn with_result_mut<Callback, R, E>( &self, _result: &mut Result<Root, E>, _f: Callback, ) -> Option<R>
where Callback: FnOnce(&mut Value) -> R,

Execute a closure with a mutable reference to the value inside a Result
Source§

fn with_option<Callback, R>( &self, option: &Option<Root>, f: Callback, ) -> Option<R>
where Callback: FnOnce(&Value) -> R,

Execute a closure with a reference to the value inside an Option
Source§

fn with_option_mut<Callback, R>( &self, _option: &mut Option<Root>, _f: Callback, ) -> Option<R>
where Callback: FnOnce(&mut Value) -> R,

Execute a closure with a mutable reference to the value inside an Option
Source§

fn with_refcell<Callback, R>( &self, refcell: &RefCell<Root>, f: Callback, ) -> Option<R>
where Callback: FnOnce(&Value) -> R,

Execute a closure with a reference to the value inside a RefCell
Source§

fn with_refcell_mut<Callback, R>( &self, _refcell: &RefCell<Root>, _f: Callback, ) -> Option<R>
where Callback: FnOnce(&mut Value) -> R,

Execute a closure with a mutable reference to the value inside a RefCell
Source§

fn with_mutex<Callback, R>(&self, mutex: &Mutex<Root>, f: Callback) -> Option<R>
where Callback: FnOnce(&Value) -> R,

Execute a closure with a reference to the value inside a Mutex
Source§

fn with_mutex_mut<Callback, R>( &self, _mutex: &mut Mutex<Root>, _f: Callback, ) -> Option<R>
where Callback: FnOnce(&mut Value) -> R,

Execute a closure with a mutable reference to the value inside a Mutex
Source§

fn with_rwlock<Callback, R>( &self, rwlock: &RwLock<Root>, f: Callback, ) -> Option<R>
where Callback: FnOnce(&Value) -> R,

Execute a closure with a reference to the value inside an RwLock
Source§

fn with_rwlock_mut<Callback, R>( &self, _rwlock: &mut RwLock<Root>, _f: Callback, ) -> Option<R>
where Callback: FnOnce(&mut Value) -> R,

Execute a closure with a mutable reference to the value inside an RwLock
Source§

fn with_arc_rwlock<Callback, R>( &self, arc_rwlock: &Arc<RwLock<Root>>, f: Callback, ) -> Option<R>
where Callback: FnOnce(&Value) -> R,

Execute a closure with a reference to the value inside an Arc<RwLock>
Source§

fn with_arc_rwlock_mut<Callback, R>( &self, _arc_rwlock: &Arc<RwLock<Root>>, _f: Callback, ) -> Option<R>
where Callback: FnOnce(&mut Value) -> R,

Execute a closure with a mutable reference to the value inside an Arc<RwLock>

Auto Trait Implementations§

§

impl<Root, Value, F> Freeze for OptionalKeyPath<Root, Value, F>
where F: Freeze,

§

impl<Root, Value, F> RefUnwindSafe for OptionalKeyPath<Root, Value, F>
where F: RefUnwindSafe, Root: RefUnwindSafe, Value: RefUnwindSafe,

§

impl<Root, Value, F> Send for OptionalKeyPath<Root, Value, F>
where F: Send, Root: Send, Value: Send,

§

impl<Root, Value, F> Sync for OptionalKeyPath<Root, Value, F>
where F: Sync, Root: Sync, Value: Sync,

§

impl<Root, Value, F> Unpin for OptionalKeyPath<Root, Value, F>
where F: Unpin, Root: Unpin, Value: Unpin,

§

impl<Root, Value, F> UnwindSafe for OptionalKeyPath<Root, Value, F>
where F: UnwindSafe, Root: UnwindSafe, Value: UnwindSafe,

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.