Lens

Struct Lens 

Source
pub struct Lens<Root, Value> {
    pub get: fn(&Root) -> &Value,
    pub set: fn(&mut Root, Value),
}
Expand description

A Lens represents a getter + setter for a field in Root.

Fields§

§get: fn(&Root) -> &Value§set: fn(&mut Root, Value)

Implementations§

Source§

impl<Root, Value> Lens<Root, Value>

Source

pub fn new(get: fn(&Root) -> &Value, set: fn(&mut Root, Value)) -> Self

Source

pub fn get_fn(&self) -> impl Fn(&Root) -> &Value

Getter: like Swift get(\.field)

Source

pub fn over( &self, update: impl Fn(Value) -> Value + 'static + Clone, ) -> impl Fn(Root) -> Root
where Root: Clone, Value: Clone,

Immutable setter: like Swift prop(\.field)

Source

pub fn set_value(&self, value: Value) -> impl Fn(Root) -> Root
where Root: Clone, Value: Clone + 'static,

Set a constant value: like Swift set(\.field, value)

Source

pub fn mver( &self, update: impl Fn(&mut Value) + 'static + Clone, ) -> impl Fn(&mut Root)
where Root: Clone, Value: Clone,

Mutable in-place setter: like Swift mprop

Auto Trait Implementations§

§

impl<Root, Value> Freeze for Lens<Root, Value>

§

impl<Root, Value> RefUnwindSafe for Lens<Root, Value>

§

impl<Root, Value> Send for Lens<Root, Value>

§

impl<Root, Value> Sync for Lens<Root, Value>

§

impl<Root, Value> Unpin for Lens<Root, Value>

§

impl<Root, Value> UnwindSafe for Lens<Root, Value>

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> 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, 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.