pub struct WritableOptionalKeyPath<Root, Value, F>{ /* private fields */ }Implementations§
Source§impl<Root, Value, F> WritableOptionalKeyPath<Root, Value, F>
impl<Root, Value, F> WritableOptionalKeyPath<Root, Value, F>
pub fn new(getter: F) -> Self
pub fn get_mut<'r>(&self, root: &'r mut Root) -> Option<&'r mut Value>
Sourcepub fn trace_chain(&self, root: &mut Root) -> Result<(), String>
pub fn trace_chain(&self, root: &mut Root) -> Result<(), String>
Trace the chain to find where it breaks Returns Ok(()) if the chain succeeds, or Err with diagnostic information
§Example
let path = SomeComplexStruct::scsf_fw()
.then(SomeOtherStruct::sosf_fw())
.then(SomeEnum::b_case_fw());
match path.trace_chain(&mut instance) {
Ok(()) => println!("Chain succeeded"),
Err(msg) => println!("Chain broken: {}", msg),
}Sourcepub fn for_option(
self,
) -> WritableOptionalKeyPath<Option<Root>, Value, impl for<'r> Fn(&'r mut Option<Root>) -> Option<&'r mut Value> + 'static>where
F: 'static,
Root: 'static,
Value: 'static,
pub fn for_option(
self,
) -> WritableOptionalKeyPath<Option<Root>, Value, impl for<'r> Fn(&'r mut Option<Root>) -> Option<&'r mut Value> + 'static>where
F: 'static,
Root: 'static,
Value: 'static,
Adapt this keypath to work with Option
pub fn then<SubValue, G>(
self,
next: WritableOptionalKeyPath<Value, SubValue, G>,
) -> WritableOptionalKeyPath<Root, SubValue, impl for<'r> Fn(&'r mut Root) -> Option<&'r mut SubValue>>where
G: for<'r> Fn(&'r mut Value) -> Option<&'r mut SubValue> + 'static,
F: 'static,
Value: 'static,
pub fn for_box<Target>(
self,
) -> WritableOptionalKeyPath<Root, Target, impl for<'r> Fn(&'r mut Root) -> Option<&'r mut Target> + 'static>where
Value: DerefMut<Target = Target> + 'static,
F: 'static,
pub fn for_arc<Target>(
self,
) -> WritableOptionalKeyPath<Root, Target, impl for<'r> Fn(&'r mut Root) -> Option<&'r mut Target> + 'static>where
Value: DerefMut<Target = Target> + 'static,
F: 'static,
pub fn for_rc<Target>(
self,
) -> WritableOptionalKeyPath<Root, Target, impl for<'r> Fn(&'r mut Root) -> Option<&'r mut Target> + 'static>where
Value: DerefMut<Target = Target> + 'static,
F: 'static,
Sourcepub fn for_result<E>(
self,
) -> WritableOptionalKeyPath<Result<Root, E>, Value, impl for<'r> Fn(&'r mut Result<Root, E>) -> Option<&'r mut Value> + 'static>where
F: 'static,
Root: 'static,
Value: 'static,
E: 'static,
pub fn for_result<E>(
self,
) -> WritableOptionalKeyPath<Result<Root, E>, Value, impl for<'r> Fn(&'r mut Result<Root, E>) -> Option<&'r mut 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
pub fn for_box_root(
self,
) -> WritableOptionalKeyPath<Box<Root>, Value, impl for<'r> Fn(&'r mut Box<Root>) -> Option<&'r mut Value> + 'static>where
Value: Sized + 'static,
F: 'static,
Root: 'static,
pub fn for_arc_root(
self,
) -> WritableOptionalKeyPath<Arc<Root>, Value, impl for<'r> Fn(&'r mut Arc<Root>) -> Option<&'r mut Value> + 'static>where
Value: Sized + 'static,
F: 'static,
Root: 'static,
pub fn for_rc_root(
self,
) -> WritableOptionalKeyPath<Rc<Root>, Value, impl for<'r> Fn(&'r mut Rc<Root>) -> Option<&'r mut Value> + 'static>where
Value: Sized + 'static,
F: 'static,
Root: 'static,
Source§impl WritableOptionalKeyPath<(), (), fn(&mut ()) -> Option<&mut ()>>
impl WritableOptionalKeyPath<(), (), fn(&mut ()) -> Option<&mut ()>>
pub fn for_option_static<T>() -> WritableOptionalKeyPath<Option<T>, T, impl for<'r> Fn(&'r mut Option<T>) -> Option<&'r mut T>>
Sourcepub fn writable_enum<Enum, Variant, EmbedFn, ReadExtractFn, WriteExtractFn>(
_embedder: EmbedFn,
_read_extractor: ReadExtractFn,
write_extractor: WriteExtractFn,
) -> WritableOptionalKeyPath<Enum, Variant, impl for<'r> Fn(&'r mut Enum) -> Option<&'r mut Variant> + 'static>where
EmbedFn: Fn(Variant) -> Enum + 'static,
ReadExtractFn: for<'r> Fn(&'r Enum) -> Option<&'r Variant> + 'static,
WriteExtractFn: for<'r> Fn(&'r mut Enum) -> Option<&'r mut Variant> + 'static,
pub fn writable_enum<Enum, Variant, EmbedFn, ReadExtractFn, WriteExtractFn>(
_embedder: EmbedFn,
_read_extractor: ReadExtractFn,
write_extractor: WriteExtractFn,
) -> WritableOptionalKeyPath<Enum, Variant, impl for<'r> Fn(&'r mut Enum) -> Option<&'r mut Variant> + 'static>where
EmbedFn: Fn(Variant) -> Enum + 'static,
ReadExtractFn: for<'r> Fn(&'r Enum) -> Option<&'r Variant> + 'static,
WriteExtractFn: for<'r> Fn(&'r mut Enum) -> Option<&'r mut Variant> + 'static,
Backword compatibility method for writable enum keypath This allows both reading and writing to enum variant fields
§Arguments
embedder- Function to embed a value into the enum variant (for API consistency, not used)read_extractor- Function to extract a read reference from the enum (for API consistency, not used)write_extractor- Function to extract a mutable reference from the enum
§Example
enum Color { Other(RGBU8) }
struct RGBU8(u8, u8, u8);
let case_path = WritableOptionalKeyPath::writable_enum(
|v| Color::Other(v),
|p: &Color| match p { Color::Other(rgb) => Some(rgb), _ => None },
|p: &mut Color| match p { Color::Other(rgb) => Some(rgb), _ => None },
);Source§impl<Root, Value, F> WritableOptionalKeyPath<Root, Value, F>where
F: for<'r> Fn(&'r mut Root) -> Option<&'r mut Value> + 'static,
Root: Any + 'static,
Value: Any + 'static,
impl<Root, Value, F> WritableOptionalKeyPath<Root, Value, F>where
F: for<'r> Fn(&'r mut Root) -> Option<&'r mut Value> + 'static,
Root: Any + 'static,
Value: Any + 'static,
Sourcepub fn to_partial(self) -> PartialWritableOptionalKeyPath<Root>
pub fn to_partial(self) -> PartialWritableOptionalKeyPath<Root>
Convert to PartialWritableOptionalKeyPath (hides Value type)
Sourcepub fn to_any(self) -> AnyWritableKeyPath
pub fn to_any(self) -> AnyWritableKeyPath
Convert to AnyWritableKeyPath (hides both Root and Value types)
Sourcepub fn to(self) -> PartialWritableOptionalKeyPath<Root>
pub fn to(self) -> PartialWritableOptionalKeyPath<Root>
Convert to PartialWritableOptionalKeyPath (alias for to_partial())
Trait Implementations§
Source§impl<Root: Clone, Value: Clone, F> Clone for WritableOptionalKeyPath<Root, Value, F>
impl<Root: Clone, Value: Clone, F> Clone for WritableOptionalKeyPath<Root, Value, F>
Source§fn clone(&self) -> WritableOptionalKeyPath<Root, Value, F>
fn clone(&self) -> WritableOptionalKeyPath<Root, Value, F>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<Root, Value, F> Debug for WritableOptionalKeyPath<Root, Value, F>
impl<Root, Value, F> Debug for WritableOptionalKeyPath<Root, Value, F>
Source§impl<Root, Value, F> Display for WritableOptionalKeyPath<Root, Value, F>
impl<Root, Value, F> Display for WritableOptionalKeyPath<Root, Value, F>
Source§impl<Root, Value, F> WithContainer<Root, Value> for WritableOptionalKeyPath<Root, Value, F>
impl<Root, Value, F> WithContainer<Root, Value> for WritableOptionalKeyPath<Root, Value, F>
Source§fn with_arc<Callback, R>(&self, _arc: &Arc<Root>, _f: Callback) -> R
fn with_arc<Callback, R>(&self, _arc: &Arc<Root>, _f: Callback) -> 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
fn with_box<Callback, R>(&self, _boxed: &Box<Root>, _f: Callback) -> 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) -> Rwhere
Callback: FnOnce(&mut Value) -> R,
fn with_box_mut<Callback, R>(&self, boxed: &mut Box<Root>, f: Callback) -> Rwhere
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
fn with_rc<Callback, R>(&self, _rc: &Rc<Root>, _f: Callback) -> 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>
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
Source§fn with_result_mut<Callback, R, E>(
&self,
result: &mut Result<Root, E>,
f: Callback,
) -> Option<R>where
Callback: FnOnce(&mut Value) -> R,
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>
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
Source§fn with_option_mut<Callback, R>(
&self,
option: &mut Option<Root>,
f: Callback,
) -> Option<R>where
Callback: FnOnce(&mut Value) -> R,
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>
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
Source§fn with_refcell_mut<Callback, R>(
&self,
refcell: &RefCell<Root>,
f: Callback,
) -> Option<R>where
Callback: FnOnce(&mut Value) -> R,
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>
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
Source§fn with_mutex_mut<Callback, R>(
&self,
mutex: &mut Mutex<Root>,
f: Callback,
) -> Option<R>where
Callback: FnOnce(&mut Value) -> R,
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>
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
Source§fn with_rwlock_mut<Callback, R>(
&self,
rwlock: &mut RwLock<Root>,
f: Callback,
) -> Option<R>where
Callback: FnOnce(&mut Value) -> R,
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>
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>
Source§fn with_arc_rwlock_mut<Callback, R>(
&self,
arc_rwlock: &Arc<RwLock<Root>>,
f: Callback,
) -> Option<R>where
Callback: FnOnce(&mut Value) -> R,
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 WritableOptionalKeyPath<Root, Value, F>where
F: Freeze,
impl<Root, Value, F> RefUnwindSafe for WritableOptionalKeyPath<Root, Value, F>
impl<Root, Value, F> Send for WritableOptionalKeyPath<Root, Value, F>
impl<Root, Value, F> Sync for WritableOptionalKeyPath<Root, Value, F>
impl<Root, Value, F> Unpin for WritableOptionalKeyPath<Root, Value, F>
impl<Root, Value, F> UnwindSafe for WritableOptionalKeyPath<Root, Value, F>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more