pub enum KeyPaths<Root, Value> {
Readable(Rc<dyn for<'a> Fn(&'a Root) -> &'a Value>),
ReadableEnum {
extract: Rc<dyn for<'a> Fn(&'a Root) -> Option<&'a Value>>,
embed: Rc<dyn Fn(Value) -> Root>,
},
FailableReadable(Rc<dyn for<'a> Fn(&'a Root) -> Option<&'a Value>>),
Writable(Rc<dyn for<'a> Fn(&'a mut Root) -> &'a mut Value>),
FailableWritable(Rc<dyn for<'a> Fn(&'a mut Root) -> Option<&'a mut Value>>),
WritableEnum {
extract: Rc<dyn for<'a> Fn(&'a Root) -> Option<&'a Value>>,
extract_mut: Rc<dyn for<'a> Fn(&'a mut Root) -> Option<&'a mut Value>>,
embed: Rc<dyn Fn(Value) -> Root>,
},
Owned(Rc<dyn Fn(Root) -> Value>),
FailableOwned(Rc<dyn Fn(Root) -> Option<Value>>),
}Expand description
Go to examples section to see the implementations
Variants§
Readable(Rc<dyn for<'a> Fn(&'a Root) -> &'a Value>)
ReadableEnum
FailableReadable(Rc<dyn for<'a> Fn(&'a Root) -> Option<&'a Value>>)
Writable(Rc<dyn for<'a> Fn(&'a mut Root) -> &'a mut Value>)
FailableWritable(Rc<dyn for<'a> Fn(&'a mut Root) -> Option<&'a mut Value>>)
WritableEnum
Fields
extract_mut: Rc<dyn for<'a> Fn(&'a mut Root) -> Option<&'a mut Value>>Owned(Rc<dyn Fn(Root) -> Value>)
FailableOwned(Rc<dyn Fn(Root) -> Option<Value>>)
Implementations§
Source§impl<Root, Value> KeyPaths<Root, Value>
impl<Root, Value> KeyPaths<Root, Value>
pub fn readable( get: impl for<'a> Fn(&'a Root) -> &'a Value + 'static, ) -> KeyPaths<Root, Value>
pub fn writable( get_mut: impl for<'a> Fn(&'a mut Root) -> &'a mut Value + 'static, ) -> KeyPaths<Root, Value>
pub fn failable_readable( get: impl for<'a> Fn(&'a Root) -> Option<&'a Value> + 'static, ) -> KeyPaths<Root, Value>
pub fn failable_writable( get_mut: impl for<'a> Fn(&'a mut Root) -> Option<&'a mut Value> + 'static, ) -> KeyPaths<Root, Value>
pub fn readable_enum( embed: impl Fn(Value) -> Root + 'static, extract: impl for<'a> Fn(&'a Root) -> Option<&'a Value> + 'static, ) -> KeyPaths<Root, Value>
pub fn writable_enum( embed: impl Fn(Value) -> Root + 'static, extract: impl for<'a> Fn(&'a Root) -> Option<&'a Value> + 'static, extract_mut: impl for<'a> Fn(&'a mut Root) -> Option<&'a mut Value> + 'static, ) -> KeyPaths<Root, Value>
pub fn owned(get: impl Fn(Root) -> Value + 'static) -> KeyPaths<Root, Value>
pub fn failable_owned( get: impl Fn(Root) -> Option<Value> + 'static, ) -> KeyPaths<Root, Value>
pub fn owned_writable( get: impl Fn(Root) -> Value + 'static, ) -> KeyPaths<Root, Value>
pub fn failable_owned_writable( get: impl Fn(Root) -> Option<Value> + 'static, ) -> KeyPaths<Root, Value>
Source§impl<Root, Value> KeyPaths<Root, Value>
impl<Root, Value> KeyPaths<Root, Value>
Sourcepub fn get<'a>(&'a self, root: &'a Root) -> Option<&'a Value>
pub fn get<'a>(&'a self, root: &'a Root) -> Option<&'a Value>
Get an immutable reference if possible
Sourcepub fn get_ref<'a, 'b>(&'a self, root: &'b &Root) -> Option<&'b Value>where
'a: 'b,
pub fn get_ref<'a, 'b>(&'a self, root: &'b &Root) -> Option<&'b Value>where
'a: 'b,
Get an immutable reference when Root is itself a reference (&T) This enables using keypaths with collections of references like Vec<&T>
Sourcepub fn get_mut<'a>(&'a self, root: &'a mut Root) -> Option<&'a mut Value>
pub fn get_mut<'a>(&'a self, root: &'a mut Root) -> Option<&'a mut Value>
Get a mutable reference if possible
Sourcepub fn get_mut_ref<'a, 'b>(
&'a self,
root: &'b mut &mut Root,
) -> Option<&'b mut Value>where
'a: 'b,
pub fn get_mut_ref<'a, 'b>(
&'a self,
root: &'b mut &mut Root,
) -> Option<&'b mut Value>where
'a: 'b,
Get a mutable reference when Root is itself a mutable reference (&mut T) This enables using writable keypaths with collections of mutable references
Sourcepub fn for_arc(self) -> KeyPaths<Arc<Root>, Value>where
Root: 'static,
Value: 'static,
pub fn for_arc(self) -> KeyPaths<Arc<Root>, Value>where
Root: 'static,
Value: 'static,
Adapt this keypath to work with Arc
Sourcepub fn for_box(self) -> KeyPaths<Box<Root>, Value>where
Root: 'static,
Value: 'static,
pub fn for_box(self) -> KeyPaths<Box<Root>, Value>where
Root: 'static,
Value: 'static,
Adapt this keypath to work with Box
Sourcepub fn for_rc(self) -> KeyPaths<Rc<Root>, Value>where
Root: 'static,
Value: 'static,
pub fn for_rc(self) -> KeyPaths<Rc<Root>, Value>where
Root: 'static,
Value: 'static,
Adapt this keypath to work with Rc
Sourcepub fn for_result<E>(self) -> KeyPaths<Result<Root, E>, Value>where
Root: 'static,
Value: 'static,
E: 'static,
pub fn for_result<E>(self) -> KeyPaths<Result<Root, E>, Value>where
Root: 'static,
Value: 'static,
E: 'static,
Adapt this keypath to work with Result<Root, E> Enables using KeyPaths<T, V> with Result types Note: This creates a FailableReadable keypath since Result can be Err
Sourcepub fn for_option(self) -> KeyPaths<Option<Root>, Value>where
Root: 'static,
Value: 'static,
pub fn for_option(self) -> KeyPaths<Option<Root>, Value>where
Root: 'static,
Value: 'static,
Adapt this keypath to work with Option
Sourcepub fn for_arc_rwlock(self) -> KeyPaths<Arc<RwLock<Root>>, Value>where
Root: 'static,
Value: Clone + 'static,
pub fn for_arc_rwlock(self) -> KeyPaths<Arc<RwLock<Root>>, Value>where
Root: 'static,
Value: Clone + 'static,
Adapt this keypath to work with Arc<RwLock
Sourcepub fn for_arc_mutex(self) -> KeyPaths<Arc<Mutex<Root>>, Value>where
Root: 'static,
Value: Clone + 'static,
pub fn for_arc_mutex(self) -> KeyPaths<Arc<Mutex<Root>>, Value>where
Root: 'static,
Value: Clone + 'static,
Adapt this keypath to work with Arc<Mutex
Sourcepub fn for_tagged<Tag>(self) -> KeyPaths<Tagged<Root, Tag>, Value>where
Root: Clone + 'static,
Value: 'static,
Tag: 'static,
pub fn for_tagged<Tag>(self) -> KeyPaths<Tagged<Root, Tag>, Value>where
Root: Clone + 'static,
Value: 'static,
Tag: 'static,
Adapt a keypath to work with Tagged<Tag, Root> Returns a new KeyPaths instance that can work with Tagged values Note: Tagged<T, Tag> where T is the actual value and Tag is a zero-sized phantom type Tagged only implements Deref, not DerefMut, so writable keypaths are not supported
pub fn embed(&self, value: Value) -> Option<Root>where
Value: Clone,
pub fn embed_mut(&self, value: Value) -> Option<Root>where
Value: Clone,
Sourcepub fn get_owned(self, root: Root) -> Value
pub fn get_owned(self, root: Root) -> Value
Get an owned value (primary method for owned keypaths)
Sourcepub fn get_failable_owned(self, root: Root) -> Option<Value>
pub fn get_failable_owned(self, root: Root) -> Option<Value>
Get an owned value with failable access
Sourcepub fn iter<'a, T>(
&'a self,
root: &'a Root,
) -> Option<<&'a Value as IntoIterator>::IntoIter>
pub fn iter<'a, T>( &'a self, root: &'a Root, ) -> Option<<&'a Value as IntoIterator>::IntoIter>
Iter over immutable references if Value: IntoIterator
Sourcepub fn iter_mut<'a, T>(
&'a self,
root: &'a mut Root,
) -> Option<<&'a mut Value as IntoIterator>::IntoIter>
pub fn iter_mut<'a, T>( &'a self, root: &'a mut Root, ) -> Option<<&'a mut Value as IntoIterator>::IntoIter>
Iter over mutable references if &mut Value: IntoIterator
Sourcepub fn into_iter<T>(
self,
root: Root,
) -> Option<<Value as IntoIterator>::IntoIter>where
Value: IntoIterator<Item = T> + Clone,
pub fn into_iter<T>(
self,
root: Root,
) -> Option<<Value as IntoIterator>::IntoIter>where
Value: IntoIterator<Item = T> + Clone,
Consume root and iterate if Value: IntoIterator
Source§impl<Root, Mid> KeyPaths<Root, Mid>where
Root: 'static,
Mid: 'static,
impl<Root, Mid> KeyPaths<Root, Mid>where
Root: 'static,
Mid: 'static,
Trait Implementations§
Source§impl<Root, Value> WithContainer<Root, Value> for KeyPaths<Root, Value>
impl<Root, Value> WithContainer<Root, Value> for KeyPaths<Root, Value>
Source§fn with_arc<F, R>(self, arc: &Arc<Root>, f: F) -> R
fn with_arc<F, R>(self, arc: &Arc<Root>, f: F) -> R
Execute a closure with a reference to the value inside an Arc This avoids cloning by working with references directly
Source§fn with_box<F, R>(self, boxed: &Box<Root>, f: F) -> R
fn with_box<F, R>(self, boxed: &Box<Root>, f: F) -> R
Execute a closure with a reference to the value inside a Box This avoids cloning by working with references directly
Source§fn with_box_mut<F, R>(self, boxed: &mut Box<Root>, f: F) -> Rwhere
F: FnOnce(&mut Value) -> R,
fn with_box_mut<F, R>(self, boxed: &mut Box<Root>, f: F) -> Rwhere
F: FnOnce(&mut Value) -> R,
Execute a closure with a mutable reference to the value inside a Box This avoids cloning by working with references directly
Source§fn with_rc<F, R>(self, rc: &Rc<Root>, f: F) -> R
fn with_rc<F, R>(self, rc: &Rc<Root>, f: F) -> R
Execute a closure with a reference to the value inside an Rc This avoids cloning by working with references directly
Source§fn with_result<F, R, E>(self, result: &Result<Root, E>, f: F) -> Option<R>
fn with_result<F, R, E>(self, result: &Result<Root, E>, f: F) -> Option<R>
Execute a closure with a reference to the value inside a Result This avoids cloning by working with references directly
Source§fn with_result_mut<F, R, E>(
self,
result: &mut Result<Root, E>,
f: F,
) -> Option<R>where
F: FnOnce(&mut Value) -> R,
fn with_result_mut<F, R, E>(
self,
result: &mut Result<Root, E>,
f: F,
) -> Option<R>where
F: FnOnce(&mut Value) -> R,
Execute a closure with a mutable reference to the value inside a Result This avoids cloning by working with references directly
Source§fn with_option<F, R>(self, option: &Option<Root>, f: F) -> Option<R>
fn with_option<F, R>(self, option: &Option<Root>, f: F) -> Option<R>
Execute a closure with a reference to the value inside an Option This avoids cloning by working with references directly
Source§fn with_option_mut<F, R>(self, option: &mut Option<Root>, f: F) -> Option<R>where
F: FnOnce(&mut Value) -> R,
fn with_option_mut<F, R>(self, option: &mut Option<Root>, f: F) -> Option<R>where
F: FnOnce(&mut Value) -> R,
Execute a closure with a mutable reference to the value inside an Option This avoids cloning by working with references directly
Source§fn with_refcell<F, R>(self, refcell: &RefCell<Root>, f: F) -> Option<R>
fn with_refcell<F, R>(self, refcell: &RefCell<Root>, f: F) -> Option<R>
Execute a closure with a reference to the value inside a RefCell This avoids cloning by working with references directly
Source§fn with_refcell_mut<F, R>(self, refcell: &RefCell<Root>, f: F) -> Option<R>where
F: FnOnce(&mut Value) -> R,
fn with_refcell_mut<F, R>(self, refcell: &RefCell<Root>, f: F) -> Option<R>where
F: FnOnce(&mut Value) -> R,
Execute a closure with a mutable reference to the value inside a RefCell This avoids cloning by working with references directly
Source§fn with_tagged<F, R, Tag>(self, tagged: &Tagged<Root, Tag>, f: F) -> R
fn with_tagged<F, R, Tag>(self, tagged: &Tagged<Root, Tag>, f: F) -> R
Execute a closure with a reference to the value inside a Tagged This avoids cloning by working with references directly
Source§fn with_mutex<F, R>(self, mutex: &Mutex<Root>, f: F) -> Option<R>
fn with_mutex<F, R>(self, mutex: &Mutex<Root>, f: F) -> Option<R>
Execute a closure with a reference to the value inside a Mutex This avoids cloning by working with references while the guard is alive
Source§fn with_mutex_mut<F, R>(self, mutex: &mut Mutex<Root>, f: F) -> Option<R>where
F: FnOnce(&mut Value) -> R,
fn with_mutex_mut<F, R>(self, mutex: &mut Mutex<Root>, f: F) -> Option<R>where
F: FnOnce(&mut Value) -> R,
Execute a closure with a mutable reference to the value inside a Mutex This avoids cloning by working with references while the guard is alive
Source§fn with_rwlock<F, R>(self, rwlock: &RwLock<Root>, f: F) -> Option<R>
fn with_rwlock<F, R>(self, rwlock: &RwLock<Root>, f: F) -> Option<R>
Execute a closure with a reference to the value inside an RwLock This avoids cloning by working with references while the guard is alive
Source§fn with_rwlock_mut<F, R>(self, rwlock: &mut RwLock<Root>, f: F) -> Option<R>where
F: FnOnce(&mut Value) -> R,
fn with_rwlock_mut<F, R>(self, rwlock: &mut RwLock<Root>, f: F) -> Option<R>where
F: FnOnce(&mut Value) -> R,
Execute a closure with a mutable reference to the value inside an RwLock This avoids cloning by working with references while the guard is alive
Source§fn with_arc_rwlock<F, R>(
self,
arc_rwlock: &Arc<RwLock<Root>>,
f: F,
) -> Option<R>
fn with_arc_rwlock<F, R>( self, arc_rwlock: &Arc<RwLock<Root>>, f: F, ) -> Option<R>
Execute a closure with a reference to the value inside an Arc<RwLock
Source§fn with_arc_rwlock_mut<F, R>(
self,
arc_rwlock: &Arc<RwLock<Root>>,
f: F,
) -> Option<R>where
F: FnOnce(&mut Value) -> R,
fn with_arc_rwlock_mut<F, R>(
self,
arc_rwlock: &Arc<RwLock<Root>>,
f: F,
) -> Option<R>where
F: FnOnce(&mut Value) -> R,
Execute a closure with a mutable reference to the value inside an Arc<RwLock