Skip to main content

Iso

Struct Iso 

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

An isomorphism witnesses that S and A are “the same” structure.

Only requires Profunctor — the weakest constraint of any optic.

S — source, T — modified source, A — focus, B — replacement.

Implementations§

Source§

impl<S, T, A, B> Iso<S, T, A, B>

Source

pub fn new(forward: fn(&S) -> A, backward: fn(B) -> T) -> Iso<S, T, A, B>

Source

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

Extract the focus from a source.

Source

pub fn review(&self, b: B) -> T

Construct a source from a focus value (the reverse direction).

Source

pub fn set(&self, _s: S, b: B) -> T

Set the focus, discarding the old value.

Source

pub fn transform<P>(&self, pab: <P as HKT2>::P<A, B>) -> <P as HKT2>::P<S, T>
where P: Profunctor, S: 'static, T: 'static, A: 'static, B: 'static,

Profunctor encoding: transform a P<A, B> into a P<S, T>.

Only requires Profunctor — no Strong or Choice needed.

Source

pub fn to_getter(&self) -> Getter<S, A>

Convert to a Getter.

Source

pub fn to_review(&self) -> Review<T, B>

Convert to a Review.

Source

pub fn to_fold(&self) -> Fold<S, A>
where S: 'static, A: 'static,

Convert to a Fold (single-element).

Source§

impl<S, T, A, B> Iso<S, T, A, B>
where S: Clone,

Source

pub fn over(&self, s: S, f: impl FnOnce(A) -> B) -> T

Modify the focus.

Source

pub fn to_lens(&self) -> ComposedLens<S, T, A, B>
where S: 'static, T: 'static, A: 'static, B: 'static,

Convert to a ComposedLens (uses boxed closures since iso’s backward doesn’t match lens’s fn(S, B) -> T signature).

Source

pub fn to_setter(&self) -> Setter<S, T, A, B>
where S: 'static, T: 'static, A: 'static, B: 'static,

Convert to a Setter.

Source

pub fn to_traversal(&self) -> Traversal<S, T, A, B>
where S: 'static, T: 'static, A: 'static, B: 'static,

Convert to a Traversal (single-element).

Trait Implementations§

Source§

impl<S, T, A, B> Optic for Iso<S, T, A, B>

Auto Trait Implementations§

§

impl<S, T, A, B> Freeze for Iso<S, T, A, B>

§

impl<S, T, A, B> RefUnwindSafe for Iso<S, T, A, B>

§

impl<S, T, A, B> Send for Iso<S, T, A, B>

§

impl<S, T, A, B> Sync for Iso<S, T, A, B>

§

impl<S, T, A, B> Unpin for Iso<S, T, A, B>

§

impl<S, T, A, B> UnsafeUnpin for Iso<S, T, A, B>

§

impl<S, T, A, B> UnwindSafe for Iso<S, T, A, B>

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.