WritableOptionalKeyPath

Struct WritableOptionalKeyPath 

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

Implementations§

Source§

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

Source

pub fn new(getter: F) -> WritableOptionalKeyPath<Root, Value, F>

Source

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

Source

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),
}
Source

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 instead of Root This unwraps the Option and applies the keypath to the Some value

Source

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,

Source

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,

Source

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,

Source

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,

Source

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

Source

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,

Source

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,

Source

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,

Source

pub fn to_arc_rwlock_kp<InnerValue>( self, ) -> WritableOptionalKeyPath<Root, Value, F>
where Value: Borrow<Arc<RwLock<InnerValue>>>,

Convert this writable optional keypath to an Arc chain-ready keypath Returns self, but serves as a marker for intent and enables chaining

Source

pub fn to_arc_mutex_kp<InnerValue>( self, ) -> WritableOptionalKeyPath<Root, Value, F>
where Value: Borrow<Arc<Mutex<InnerValue>>>,

Convert this writable optional keypath to an Arc chain-ready keypath Returns self, but serves as a marker for intent and enables chaining

Source

pub fn to_arc_parking_rwlock_kp<InnerValue>( self, ) -> WritableOptionalKeyPath<Root, Value, F>
where Value: Borrow<Arc<RwLock<RawRwLock, InnerValue>>>,

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

Source

pub fn to_arc_parking_mutex_kp<InnerValue>( self, ) -> WritableOptionalKeyPath<Root, Value, F>
where Value: Borrow<Arc<Mutex<RawMutex, InnerValue>>>,

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 ()>>

Source

pub fn for_option_static<T>() -> WritableOptionalKeyPath<Option<T>, T, impl for<'r> Fn(&'r mut Option<T>)>

Source

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,

Source

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

Convert to PartialWritableOptionalKeyPath (hides Value type)

Source

pub fn to_any(self) -> AnyWritableKeyPath

Convert to AnyWritableKeyPath (hides both Root and Value types)

Source

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>
where Root: Clone, Value: Clone, F: Clone + for<'r> Fn(&'r mut Root) -> Option<&'r mut Value>,

Source§

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)

Performs copy-assignment from source. Read more
Source§

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

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

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_tagged<Callback, R, Tag>( &self, _tagged: &Tagged<Root, Tag>, _f: Callback, ) -> R
where Tagged<Root, Tag>: Deref<Target = Root>, Callback: FnOnce(&Value) -> R,

Execute a closure with a reference to the value inside a Tagged
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 WritableOptionalKeyPath<Root, Value, F>
where F: Freeze,

§

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

§

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

§

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

§

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

§

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

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

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

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

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.