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) -> WritableOptionalKeyPath<Root, Value, F>
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>) + '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>) + '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)>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) + '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) + '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) + '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>) + '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>) + '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>) + 'static>where
F: 'static,
Root: 'static,
Value: 'static,
pub fn for_arc_root(
self,
) -> WritableOptionalKeyPath<Arc<Root>, Value, impl for<'r> Fn(&'r mut Arc<Root>) + 'static>where
F: 'static,
Root: 'static,
Value: 'static,
pub fn for_rc_root(
self,
) -> WritableOptionalKeyPath<Rc<Root>, Value, impl for<'r> Fn(&'r mut Rc<Root>) + 'static>where
F: 'static,
Root: 'static,
Value: 'static,
Sourcepub fn to_arc_rwlock_kp<InnerValue>(
self,
) -> WritableOptionalKeyPath<Root, Value, F>
pub fn to_arc_rwlock_kp<InnerValue>( self, ) -> WritableOptionalKeyPath<Root, Value, F>
Convert this writable optional keypath to an Arc
Sourcepub fn to_arc_mutex_kp<InnerValue>(
self,
) -> WritableOptionalKeyPath<Root, Value, F>
pub fn to_arc_mutex_kp<InnerValue>( self, ) -> WritableOptionalKeyPath<Root, Value, F>
Convert this writable optional keypath to an Arc
Sourcepub fn to_arc_parking_rwlock_kp<InnerValue>(
self,
) -> WritableOptionalKeyPath<Root, Value, F>
pub fn to_arc_parking_rwlock_kp<InnerValue>( self, ) -> WritableOptionalKeyPath<Root, Value, F>
Convert this writable optional keypath to an Arc<parking_lot::RwLock> chain-ready keypath Returns self, but serves as a marker for intent and enables chaining
Sourcepub fn to_arc_parking_mutex_kp<InnerValue>(
self,
) -> WritableOptionalKeyPath<Root, Value, F>
pub fn to_arc_parking_mutex_kp<InnerValue>( self, ) -> WritableOptionalKeyPath<Root, Value, F>
Convert this writable optional keypath to an Arc<parking_lot::Mutex> chain-ready keypath Returns self, but serves as a marker for intent and enables chaining
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>)>
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) + '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) + '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, Value, F> Clone for WritableOptionalKeyPath<Root, Value, F>
impl<Root, Value, F> Clone for WritableOptionalKeyPath<Root, Value, F>
Source§fn clone(&self) -> WritableOptionalKeyPath<Root, Value, F>
fn clone(&self) -> WritableOptionalKeyPath<Root, Value, F>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more