pub struct KeyPath<Root, Value, F>{ /* private fields */ }Implementations§
Source§impl<Root, Value, F> KeyPath<Root, Value, F>
impl<Root, Value, F> KeyPath<Root, Value, F>
pub fn new(getter: F) -> Self
pub fn get<'r>(&self, root: &'r Root) -> &'r Value
Sourcepub fn then_arc_mutex_at_kp<InnerValue, SubValue, G>(
self,
inner_keypath: KeyPath<InnerValue, SubValue, G>,
) -> ArcMutexKeyPathChain<Root, Value, InnerValue, SubValue, F, G>
pub fn then_arc_mutex_at_kp<InnerValue, SubValue, G>( self, inner_keypath: KeyPath<InnerValue, SubValue, G>, ) -> ArcMutexKeyPathChain<Root, Value, InnerValue, SubValue, F, G>
Chain this keypath with an inner keypath through Arc<Mutex
§Example
let container = ContainerTest { mutex_data: Arc::new(Mutex::new(SomeStruct { data: "test".to_string() })) };
// Functional style: compose first, apply container at get()
ContainerTest::mutex_data_r()
.then_arc_mutex_at_kp(SomeStruct::data_r())
.get(&container, |value| println!("Data: {}", value));Sourcepub fn then_arc_mutex_optional_at_kp<InnerValue, SubValue, G>(
self,
inner_keypath: OptionalKeyPath<InnerValue, SubValue, G>,
) -> ArcMutexOptionalKeyPathChain<Root, Value, InnerValue, SubValue, F, G>
pub fn then_arc_mutex_optional_at_kp<InnerValue, SubValue, G>( self, inner_keypath: OptionalKeyPath<InnerValue, SubValue, G>, ) -> ArcMutexOptionalKeyPathChain<Root, Value, InnerValue, SubValue, F, G>
Chain this keypath with an optional inner keypath through Arc<Mutex
§Example
let container = ContainerTest { mutex_data: Arc::new(Mutex::new(SomeStruct { optional_field: Some("test".to_string()) })) };
// Functional style: compose first, apply container at get()
ContainerTest::mutex_data_r()
.then_arc_mutex_optional_at_kp(SomeStruct::optional_field_fr())
.get(&container, |value| println!("Value: {}", value));Sourcepub fn then_arc_rwlock_at_kp<InnerValue, SubValue, G>(
self,
inner_keypath: KeyPath<InnerValue, SubValue, G>,
) -> ArcRwLockKeyPathChain<Root, Value, InnerValue, SubValue, F, G>
pub fn then_arc_rwlock_at_kp<InnerValue, SubValue, G>( self, inner_keypath: KeyPath<InnerValue, SubValue, G>, ) -> ArcRwLockKeyPathChain<Root, Value, InnerValue, SubValue, F, G>
Chain this keypath with an inner keypath through Arc<RwLock
§Example
let container = ContainerTest { rwlock_data: Arc::new(RwLock::new(SomeStruct { data: "test".to_string() })) };
// Functional style: compose first, apply container at get()
ContainerTest::rwlock_data_r()
.then_arc_rwlock_at_kp(SomeStruct::data_r())
.get(&container, |value| println!("Data: {}", value));Sourcepub fn then_arc_rwlock_optional_at_kp<InnerValue, SubValue, G>(
self,
inner_keypath: OptionalKeyPath<InnerValue, SubValue, G>,
) -> ArcRwLockOptionalKeyPathChain<Root, Value, InnerValue, SubValue, F, G>
pub fn then_arc_rwlock_optional_at_kp<InnerValue, SubValue, G>( self, inner_keypath: OptionalKeyPath<InnerValue, SubValue, G>, ) -> ArcRwLockOptionalKeyPathChain<Root, Value, InnerValue, SubValue, F, G>
Chain this keypath with an optional inner keypath through Arc<RwLock
§Example
let container = ContainerTest { rwlock_data: Arc::new(RwLock::new(SomeStruct { optional_field: Some("test".to_string()) })) };
// Functional style: compose first, apply container at get()
ContainerTest::rwlock_data_r()
.then_arc_rwlock_optional_at_kp(SomeStruct::optional_field_fr())
.get(&container, |value| println!("Value: {}", value));Sourcepub fn then_arc_mutex_writable_at_kp<InnerValue, SubValue, G>(
self,
inner_keypath: WritableKeyPath<InnerValue, SubValue, G>,
) -> ArcMutexWritableKeyPathChain<Root, Value, InnerValue, SubValue, F, G>
pub fn then_arc_mutex_writable_at_kp<InnerValue, SubValue, G>( self, inner_keypath: WritableKeyPath<InnerValue, SubValue, G>, ) -> ArcMutexWritableKeyPathChain<Root, Value, InnerValue, SubValue, F, G>
Chain this keypath with a writable inner keypath through Arc<Mutex
§Example
ContainerTest::mutex_data_r()
.then_arc_mutex_writable_at_kp(SomeStruct::data_w())
.get_mut(&container, |value| *value = "new".to_string());Sourcepub fn then_arc_mutex_writable_optional_at_kp<InnerValue, SubValue, G>(
self,
inner_keypath: WritableOptionalKeyPath<InnerValue, SubValue, G>,
) -> ArcMutexWritableOptionalKeyPathChain<Root, Value, InnerValue, SubValue, F, G>
pub fn then_arc_mutex_writable_optional_at_kp<InnerValue, SubValue, G>( self, inner_keypath: WritableOptionalKeyPath<InnerValue, SubValue, G>, ) -> ArcMutexWritableOptionalKeyPathChain<Root, Value, InnerValue, SubValue, F, G>
Chain this keypath with a writable optional inner keypath through Arc<Mutex
§Example
ContainerTest::mutex_data_r()
.then_arc_mutex_writable_optional_at_kp(SomeStruct::optional_field_fw())
.get_mut(&container, |value| *value = "new".to_string());Sourcepub fn then_arc_rwlock_writable_at_kp<InnerValue, SubValue, G>(
self,
inner_keypath: WritableKeyPath<InnerValue, SubValue, G>,
) -> ArcRwLockWritableKeyPathChain<Root, Value, InnerValue, SubValue, F, G>
pub fn then_arc_rwlock_writable_at_kp<InnerValue, SubValue, G>( self, inner_keypath: WritableKeyPath<InnerValue, SubValue, G>, ) -> ArcRwLockWritableKeyPathChain<Root, Value, InnerValue, SubValue, F, G>
Chain this keypath with a writable inner keypath through Arc<RwLock
§Example
ContainerTest::rwlock_data_r()
.then_arc_rwlock_writable_at_kp(SomeStruct::data_w())
.get_mut(&container, |value| *value = "new".to_string());Sourcepub fn then_arc_rwlock_writable_optional_at_kp<InnerValue, SubValue, G>(
self,
inner_keypath: WritableOptionalKeyPath<InnerValue, SubValue, G>,
) -> ArcRwLockWritableOptionalKeyPathChain<Root, Value, InnerValue, SubValue, F, G>
pub fn then_arc_rwlock_writable_optional_at_kp<InnerValue, SubValue, G>( self, inner_keypath: WritableOptionalKeyPath<InnerValue, SubValue, G>, ) -> ArcRwLockWritableOptionalKeyPathChain<Root, Value, InnerValue, SubValue, F, G>
Chain this keypath with a writable optional inner keypath through Arc<RwLock
§Example
ContainerTest::rwlock_data_r()
.then_arc_rwlock_writable_optional_at_kp(SomeStruct::optional_field_fw())
.get_mut(&container, |value| *value = "new".to_string());Sourcepub fn then_rwlock<InnerValue, SubValue, G>(
self,
inner_keypath: WritableKeyPath<InnerValue, SubValue, G>,
) -> ArcRwLockWritableKeyPathChain<Root, Value, InnerValue, SubValue, F, G>where
Value: Borrow<Arc<RwLock<InnerValue>>>,
G: for<'r> Fn(&'r mut InnerValue) -> &'r mut SubValue,
pub fn then_rwlock<InnerValue, SubValue, G>(
self,
inner_keypath: WritableKeyPath<InnerValue, SubValue, G>,
) -> ArcRwLockWritableKeyPathChain<Root, Value, InnerValue, SubValue, F, G>where
Value: Borrow<Arc<RwLock<InnerValue>>>,
G: for<'r> Fn(&'r mut InnerValue) -> &'r mut SubValue,
Monadic helper: shorthand for then_arc_rwlock_writable_at_kp when Value is Arc<RwLock
§Example
ContainerTest::rwlock_data_r()
.then_rwlock(SomeStruct::data_w())
.then(OtherStruct::field_w())
.get_mut(&container, |value| *value = "new".to_string());Sourcepub fn to_arc_rwlock_kp<InnerValue>(self) -> Self
pub fn to_arc_rwlock_kp<InnerValue>(self) -> Self
Sourcepub fn to_arc_mutex_kp<InnerValue>(self) -> Self
pub fn to_arc_mutex_kp<InnerValue>(self) -> Self
Convert this keypath to an Arc
Sourcepub fn to_arc_rwlock_chain<InnerValue>(
self,
) -> ArcRwLockKeyPathChain<Root, Value, InnerValue, InnerValue, F, impl for<'r> Fn(&'r InnerValue) -> &'r InnerValue + 'static>
pub fn to_arc_rwlock_chain<InnerValue>( self, ) -> ArcRwLockKeyPathChain<Root, Value, InnerValue, InnerValue, F, impl for<'r> Fn(&'r InnerValue) -> &'r InnerValue + 'static>
Convert this keypath to an Arc
§Example
Container::rwlock_data_r()
.to_arc_rwlock_chain()
.then(InnerStruct::field_r());Convert this keypath to an Arc
§Example
Container::rwlock_data_r()
.to_arc_rwlock_chain()
.then(InnerStruct::field_r());Sourcepub fn to_arc_mutex_chain<InnerValue>(
self,
) -> ArcMutexKeyPathChain<Root, Value, InnerValue, InnerValue, F, impl for<'r> Fn(&'r InnerValue) -> &'r InnerValue + 'static>
pub fn to_arc_mutex_chain<InnerValue>( self, ) -> ArcMutexKeyPathChain<Root, Value, InnerValue, InnerValue, F, impl for<'r> Fn(&'r InnerValue) -> &'r InnerValue + 'static>
Convert this keypath to an Arc
pub fn for_box<Target>(
self,
) -> KeyPath<Root, Target, impl for<'r> Fn(&'r Root) -> &'r Target + 'static>where
Value: Deref<Target = Target> + 'static,
F: 'static,
pub fn for_arc<Target>(
self,
) -> KeyPath<Root, Target, impl for<'r> Fn(&'r Root) -> &'r Target + 'static>where
Value: Deref<Target = Target> + 'static,
F: 'static,
pub fn for_rc<Target>(
self,
) -> KeyPath<Root, Target, impl for<'r> Fn(&'r Root) -> &'r Target + 'static>where
Value: Deref<Target = Target> + 'static,
F: 'static,
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,
pub fn for_box_root(
self,
) -> OptionalKeyPath<Box<Root>, Value, impl for<'r> Fn(&'r Box<Root>) -> Option<&'r Value> + 'static>where
Value: Sized + 'static,
F: 'static,
Root: 'static,
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,
Sourcepub 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,
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
Sourcepub fn to_optional(
self,
) -> OptionalKeyPath<Root, Value, impl for<'r> Fn(&'r Root) -> Option<&'r Value> + 'static>where
F: 'static,
pub fn to_optional(
self,
) -> OptionalKeyPath<Root, Value, impl for<'r> Fn(&'r Root) -> Option<&'r Value> + 'static>where
F: 'static,
Convert a KeyPath to OptionalKeyPath for chaining This allows non-optional keypaths to be chained with then()
Sourcepub fn with_option<Callback, R>(
&self,
option: &Option<Root>,
f: Callback,
) -> Option<R>
pub fn with_option<Callback, R>( &self, option: &Option<Root>, f: Callback, ) -> Option<R>
Execute a closure with a reference to the value inside an Option
Sourcepub fn with_result<Callback, R, E>(
&self,
result: &Result<Root, E>,
f: Callback,
) -> Option<R>
pub fn with_result<Callback, R, E>( &self, result: &Result<Root, E>, f: Callback, ) -> Option<R>
Execute a closure with a reference to the value inside a Result
Sourcepub fn with_box<Callback, R>(&self, boxed: &Box<Root>, f: Callback) -> R
pub fn with_box<Callback, R>(&self, boxed: &Box<Root>, f: Callback) -> R
Execute a closure with a reference to the value inside a Box
Sourcepub fn with_arc<Callback, R>(&self, arc: &Arc<Root>, f: Callback) -> R
pub fn with_arc<Callback, R>(&self, arc: &Arc<Root>, f: Callback) -> R
Execute a closure with a reference to the value inside an Arc
Sourcepub fn with_rc<Callback, R>(&self, rc: &Rc<Root>, f: Callback) -> R
pub fn with_rc<Callback, R>(&self, rc: &Rc<Root>, f: Callback) -> R
Execute a closure with a reference to the value inside an Rc
Sourcepub fn with_refcell<Callback, R>(
&self,
refcell: &RefCell<Root>,
f: Callback,
) -> Option<R>
pub fn with_refcell<Callback, R>( &self, refcell: &RefCell<Root>, f: Callback, ) -> Option<R>
Execute a closure with a reference to the value inside a RefCell
Sourcepub fn with_mutex<Callback, R>(
&self,
mutex: &Mutex<Root>,
f: Callback,
) -> Option<R>
pub fn with_mutex<Callback, R>( &self, mutex: &Mutex<Root>, f: Callback, ) -> Option<R>
Execute a closure with a reference to the value inside a Mutex
Sourcepub fn with_rwlock<Callback, R>(
&self,
rwlock: &RwLock<Root>,
f: Callback,
) -> Option<R>
pub fn with_rwlock<Callback, R>( &self, rwlock: &RwLock<Root>, f: Callback, ) -> Option<R>
Execute a closure with a reference to the value inside an RwLock
Sourcepub fn with_arc_rwlock<Callback, R>(
&self,
arc_rwlock: &Arc<RwLock<Root>>,
f: Callback,
) -> Option<R>
pub fn with_arc_rwlock<Callback, R>( &self, arc_rwlock: &Arc<RwLock<Root>>, f: Callback, ) -> Option<R>
Execute a closure with a reference to the value inside an Arc<RwLock
Sourcepub fn with_arc_mutex<Callback, R>(
&self,
arc_mutex: &Arc<Mutex<Root>>,
f: Callback,
) -> Option<R>
pub fn with_arc_mutex<Callback, R>( &self, arc_mutex: &Arc<Mutex<Root>>, f: Callback, ) -> Option<R>
Execute a closure with a reference to the value inside an Arc<Mutex
Sourcepub 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,
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
Sourcepub fn iter<'r, T>(&self, root: &'r Root) -> Option<Iter<'r, T>>
pub fn iter<'r, T>(&self, root: &'r Root) -> Option<Iter<'r, T>>
Get an iterator over a Vec when Value is Vec
Sourcepub fn extract_from_slice<'r>(&self, slice: &'r [Root]) -> Vec<&'r Value>
pub fn extract_from_slice<'r>(&self, slice: &'r [Root]) -> Vec<&'r Value>
Extract values from a slice of owned values Returns a Vec of references to the extracted values
Sourcepub fn extract_from_ref_slice<'r>(&self, slice: &'r [&Root]) -> Vec<&'r Value>
pub fn extract_from_ref_slice<'r>(&self, slice: &'r [&Root]) -> Vec<&'r Value>
Extract values from a slice of references Returns a Vec of references to the extracted values
Sourcepub fn then<SubValue, G>(
self,
next: KeyPath<Value, SubValue, G>,
) -> KeyPath<Root, SubValue, impl for<'r> Fn(&'r Root) -> &'r SubValue>
pub fn then<SubValue, G>( self, next: KeyPath<Value, SubValue, G>, ) -> KeyPath<Root, SubValue, impl for<'r> Fn(&'r Root) -> &'r SubValue>
Chain this keypath with another keypath Returns a KeyPath that chains both keypaths
Sourcepub fn then_optional<SubValue, G>(
self,
next: OptionalKeyPath<Value, SubValue, G>,
) -> OptionalKeyPath<Root, SubValue, impl for<'r> Fn(&'r Root) -> Option<&'r SubValue>>
pub fn then_optional<SubValue, G>( self, next: OptionalKeyPath<Value, SubValue, G>, ) -> OptionalKeyPath<Root, SubValue, impl for<'r> Fn(&'r Root) -> Option<&'r SubValue>>
Chain this keypath with an optional keypath Returns an OptionalKeyPath that chains both keypaths
Source§impl<Root, Value, F> KeyPath<Root, Value, F>
impl<Root, Value, F> KeyPath<Root, Value, F>
Sourcepub fn with_arc_rwlock_direct<Callback, R>(
&self,
arc_rwlock: &Arc<RwLock<Root>>,
f: Callback,
) -> Option<R>
pub fn with_arc_rwlock_direct<Callback, R>( &self, arc_rwlock: &Arc<RwLock<Root>>, f: Callback, ) -> Option<R>
Execute a closure with a reference to the value inside an Arc<RwLock
Source§impl<Root, Value, F> KeyPath<Root, Value, F>
impl<Root, Value, F> KeyPath<Root, Value, F>
Sourcepub fn to_partial(self) -> PartialKeyPath<Root>
pub fn to_partial(self) -> PartialKeyPath<Root>
Convert to PartialKeyPath (hides Value type)
Sourcepub fn to(self) -> PartialKeyPath<Root>
pub fn to(self) -> PartialKeyPath<Root>
Alias for to_partial() - converts to PartialKeyPath