IsoImpl

Struct IsoImpl 

Source
pub struct IsoImpl<S, A, ISO: Iso<S, A>>(pub ISO, _);
Expand description

A wrapper of the Iso optic implementations, encapsulating a reversible bijective conversion.

IsoImpl provides a way to define a reversible bijective conversion - optics that can be used to convert between values of type A and of type S. This struct is particularly useful in scenarios where you need to deal with data types that have multiple representations, such as a Point in cartesian and polar coordinates.

§Note

This struct is not intended to be created by users directly, but it implements a From<Iso<S,A>> so that implementors of new optic types can wrap their concrete implementation of an Iso optic.

§Type Parameters

  • S: The type the optic converts from
  • A: The type the optic converts to

§See Also

  • Iso trait for defining bijective conversions.
  • [mapped_iso] function for creating IsoImpl instances from mapping functions.

Tuple Fields§

§0: ISO

Implementations§

Source§

impl<S, I, ISO1: Iso<S, I>> IsoImpl<S, I, ISO1>

Source

pub fn compose_with_partial_getter<A, PG2: PartialGetter<I, A>>( self, other: PartialGetterImpl<I, A, PG2>, ) -> PartialGetterImpl<S, A, impl PartialGetter<S, A, GetterError = PG2::GetterError>>

Composes this IsoImpl<S,I> with a PartialGetter<I,A>, resulting in a new PartialGetter<S, A> that focuses through both optics sequentially.

The resulting PartialGetterImpl will attempt to extract a value by first applying self and then other. If the second optic fails to focus, the composition will fail to focus.

§Type Parameters
  • A: The target type of the composed optic.
  • PG2: The type of the partial getter to compose with.
§Parameters
  • other: The partial getter to compose with.
§Returns

A new PartialGetterImpl that represents the composition of self and other.

Source

pub fn compose_with_getter<A, G2: Getter<I, A>>( self, other: GetterImpl<I, A, G2>, ) -> GetterImpl<S, A, impl Getter<S, A>>

Composes this IsoImpl<S,I> with a GetterImpl<I,A>, resulting in a new GetterImpl<S, A> that focuses through both optics sequentially.

The resulting GetterImpl will extract a value by first applying self and then other.

§Type Parameters
  • A: The target type of the composed optic.
  • G2: The type of the partial getter to compose with.
§Parameters
  • other: The getter to compose with.
§Returns

A new GetterImpl that represents the composition of self and other.

Source

pub fn compose_with_setter<A, S2: Setter<I, A>>( self, other: SetterImpl<I, A, S2>, ) -> SetterImpl<S, A, impl Setter<S, A>>

Composes this IsoImpl<S,I> with a Setter<I,A>, resulting in a new Setter<S, A> that focuses through both optics sequentially.

The resulting SetterImpl will attempt to set a value by first applying self and then other.

§Type Parameters
  • A: The target type of the composed optic.
  • S2: The type of the setter to compose with.
§Parameters
  • other: The setter to compose with.
§Returns

A new SetterImpl that represents the composition of self and other.

Source

pub fn compose_with_lens<A, L2: Lens<I, A>>( self, other: LensImpl<I, A, L2>, ) -> LensImpl<S, A, impl Lens<S, A>>

Composes this IsoImpl<S,I> with a LensImpl<I,A>, resulting in a new LensImpl<S, A> that focuses through both optics sequentially.

The resulting LensImpl will extract a value by first applying self and then other.

§Type Parameters
  • A: The target type of the composed lens.
  • L2: The type of the lens to compose with.
§Parameters
  • other: The lens to compose with.
§Returns

A new LensImpl that represents the composition of self and other

Source

pub fn compose_with_prism<A, P2: Prism<I, A>>( self, other: PrismImpl<I, A, P2>, ) -> PrismImpl<S, A, impl Prism<S, A, GetterError = P2::GetterError>>

Composes this IsoImpl<S,I> with a Prism<I,A>, resulting in a new PrismImpl<S, A> that focuses through both prisms sequentially.

The resulting PrismImpl will attempt to extract a value by first applying self and then other. If the prism fails to focus, the composition will fail.

§Type Parameters
  • A: The target type of the composed prism.
  • P2: The type of the prism to compose with.
§Parameters
  • other: The prism to compose with.
§Returns

A new PrismImpl that represents the composition of self and other.

Source

pub fn compose_with_fallible_iso<A, FI2: FallibleIso<I, A>>( self, other: FallibleIsoImpl<I, A, FI2>, ) -> FallibleIsoImpl<S, A, impl FallibleIso<S, A, GetterError = FI2::GetterError, ReverseError = FI2::ReverseError>>

Composes this IsoImpl<S,I> with a FallibleIso<I,A>, resulting in a new FallibleIsoImpl<S, A> that focuses through both prisms sequentially.

The resulting FallibleIsoImpl will attempt to extract a value by first applying self and then other. If the fallible iso fails to focus, the composition will fail to focus.

§Type Parameters
  • A: The target type of the composed prism.
  • FI2: The type of the fallible iso to compose with.
§Parameters
  • other: The fallible iso to compose with.
§Returns

A new FallibleIsoImpl that represents the composition of self and other.

Source

pub fn compose_with_iso<A, ISO2: Iso<I, A>>( self, other: IsoImpl<I, A, ISO2>, ) -> IsoImpl<S, A, impl Iso<S, A>>

Composes this IsoImpl<S,I> with an IsoImpl<I,A>, resulting in a new IsoImpl<S, A> that focuses through both optics sequentially.

The resulting IsoImpl will extract a value by first applying self and then other.

§Type Parameters
  • A: The target type of the composed lens.
  • ISO2: The type of the lens to compose with.
§Parameters
  • other: The iso to compose with.
§Returns

A new IsoImpl that represents the composition of self and other

Trait Implementations§

Source§

impl<S, A, ISO: Iso<S, A>> From<ISO> for IsoImpl<S, A, ISO>

Source§

fn from(value: ISO) -> Self

Converts to this type from the input type.
Source§

impl<S, A, ISO: Iso<S, A>> HasGetter<S, A> for IsoImpl<S, A, ISO>

Source§

type GetterError = Infallible

The type of error that may occur during retrieval. Use Infallible for infallible optics.
Source§

fn try_get(&self, source: &S) -> Result<A, Self::GetterError>

Attempts to retrieve a value of type A from a source of type S. Read more
Source§

impl<S, A, ISO: Iso<S, A>> HasReverseGet<S, A> for IsoImpl<S, A, ISO>

Source§

type ReverseError = Infallible

The type of error that may occur during the reverse operation. Use Infallible for infallible optics.
Source§

fn try_reverse_get(&self, value: &A) -> Result<S, Self::ReverseError>

Attempts to reverse a value of type A back into a source of type S. Read more
Source§

impl<S, A, ISO: Iso<S, A>> HasSetter<S, A> for IsoImpl<S, A, ISO>

Source§

fn set(&self, source: &mut S, value: A)

Sets a value of type A the optic focuses on in a mutable source of type S. Read more

Auto Trait Implementations§

§

impl<S, A, ISO> Freeze for IsoImpl<S, A, ISO>
where ISO: Freeze,

§

impl<S, A, ISO> RefUnwindSafe for IsoImpl<S, A, ISO>

§

impl<S, A, ISO> Send for IsoImpl<S, A, ISO>
where ISO: Send, S: Send, A: Send,

§

impl<S, A, ISO> Sync for IsoImpl<S, A, ISO>
where ISO: Sync, S: Sync, A: Sync,

§

impl<S, A, ISO> Unpin for IsoImpl<S, A, ISO>
where ISO: Unpin, S: Unpin, A: Unpin,

§

impl<S, A, ISO> UnwindSafe for IsoImpl<S, A, ISO>
where ISO: UnwindSafe, S: UnwindSafe, A: 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S, A, T> HasOver<S, A> for T
where T: HasGetter<S, A> + HasSetter<S, A>,

Source§

fn over<F>(&self, source: &mut S, f: F)
where F: Fn(A) -> A,

Retrieves a value of type A from a source of type S. Read more
Source§

impl<S, A, T> HasTotalGetter<S, A> for T
where T: HasGetter<S, A, GetterError = Infallible>,

Source§

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

Retrieves a value of type A from a source of type S. Read more
Source§

impl<S, A, T> HasTotalReverseGet<S, A> for T
where T: HasReverseGet<S, A, ReverseError = Infallible>,

Source§

fn reverse_get(&self, value: &A) -> S

Reverses a value of type A back into a source of type S. Read more
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.
Source§

impl<S, A, FI> FallibleIso<S, A> for FI
where FI: HasGetter<S, A> + HasSetter<S, A> + HasReverseGet<S, A>,

Source§

impl<S, A, G> Getter<S, A> for G
where G: HasGetter<S, A, GetterError = Infallible>,

Source§

impl<S, A, ISO> Iso<S, A> for ISO
where ISO: HasGetter<S, A, GetterError = Infallible> + HasSetter<S, A> + HasReverseGet<S, A, ReverseError = Infallible>,

Source§

impl<S, A, L> Lens<S, A> for L
where L: HasGetter<S, A, GetterError = Infallible> + HasSetter<S, A>,

Source§

impl<S, A, PG> PartialGetter<S, A> for PG
where PG: HasGetter<S, A>,

Source§

impl<S, A, P> Prism<S, A> for P
where P: HasGetter<S, A> + HasSetter<S, A>,

Source§

impl<S, A, SETTER> Setter<S, A> for SETTER
where SETTER: HasSetter<S, A>,