Skip to main content

Lens

Struct Lens 

Source
pub struct Lens<S, A> { /* private fields */ }
Expand description

A lawful lens focusing on field A inside structure S.

Implementations§

Source§

impl<S: 'static, A: 'static> Lens<S, A>

Source

pub fn new( getter: impl Fn(&S) -> A + 'static, setter: impl Fn(A, S) -> S + 'static, ) -> Self

Create a lens from a getter and a setter.

Source

pub fn view(&self, s: &S) -> A

Get the focused value.

Source

pub fn set(&self, a: A, s: S) -> S

Set the focused value.

Source

pub fn over(&self, f: impl Fn(A) -> A, s: S) -> S
where S: Clone,

Modify the focused value.

Auto Trait Implementations§

§

impl<S, A> Freeze for Lens<S, A>

§

impl<S, A> !RefUnwindSafe for Lens<S, A>

§

impl<S, A> !Send for Lens<S, A>

§

impl<S, A> !Sync for Lens<S, A>

§

impl<S, A> Unpin for Lens<S, A>

§

impl<S, A> UnsafeUnpin for Lens<S, A>

§

impl<S, A> !UnwindSafe for Lens<S, A>

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.