FallibleIsoImpl

Struct FallibleIsoImpl 

Source
pub struct FallibleIsoImpl<S, A, FI: FallibleIso<S, A>>(pub FI, _);
Expand description

A wrapper of the FallibleIso optic implementations, encapsulating a potentially failing, reversible bijective conversion.

FallibleIsoImpl provides a way to define a potentially failing reversible bijective conversion optics that can be used to convert between values of type A and of type S where the conversion may fail. This struct is particularly useful in scenarios where you need to deal with data types that can be converted to and from other types, but the conversion may not always succeed, such as an IpAddress and a String.

§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
  • GE: The error type that can occur during the forward mapping.
  • RE: The error type that can occur during the reverse mapping.

§See Also

  • FallibleIso trait for defining bijective conversions.
  • [mapped_fallible_iso] function for creating FallibleIsoImpl instances from mapping functions.

Tuple Fields§

§0: FI

Implementations§

Source§

impl<S, I, FI1: FallibleIso<S, I>> FallibleIsoImpl<S, I, FI1>

Source

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

Composes this FallibleIsoImpl<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 either optics fails to focus, the composition will fail to focus.

§Type Parameters
  • E: The error type for the composed partial getter, which must should be able to be constructed from both FI1::GetterError and PG2::GetterError through Into::into.
  • 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.

§Note

This method uses Into::into to convert the errors from both prisms into the common error type E. If you need custom error mapping, consider using compose_with_partial_getter_with_mappers.

Source

pub fn compose_with_partial_getter_with_mappers<E, A, PG2: PartialGetter<I, A>>( self, other: PartialGetterImpl<I, A, PG2>, error_mapper_1: fn(FI1::GetterError) -> E, error_mapper_2: fn(PG2::GetterError) -> E, ) -> PartialGetterImpl<S, A, impl PartialGetter<S, A, GetterError = E>>

Composes this FallibleIsoImpl<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 either optics fails to focus, the composition will fail to focus.

§Type Parameters
  • E: The common error type for the composed partial_getter.
  • A: The target type of the composed prism.
§Parameters
  • other: The partial getter to compose with.
  • error_mapper1: A function to map FI1::GetterError into E.
  • error_mapper2: A function to map PG2::GetterError into E.
§Returns

A new PartialGetterImpl that represents the composition of self and other with custom error mapping.

§Note

This method is similar to compose_with_partial_getter, but provides the ability to specify custom functions to map the errors from each optic into a common error type.

Source

pub fn compose_with_getter<A, G2: Getter<I, A>>( self, other: GetterImpl<I, A, G2>, ) -> PartialGetterImpl<S, A, impl PartialGetter<S, A, GetterError = FI1::GetterError>>

Composes this FallibleIsoImpl<S,I> with a Getter<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 first optic fails to focus, the composition will fail to focus.

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

A new PartialGetterImpl 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 FallibleIsoImpl<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_prism<E, A, P2: Prism<I, A>>( self, other: PrismImpl<I, A, P2>, ) -> PrismImpl<S, A, impl Prism<S, A, GetterError = E>>
where E: From<FI1::GetterError> + From<P2::GetterError>,

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

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

§Type Parameters
  • E: The error type for the composed prism, which must should be able to be constructed from both FI1::GetterError and P2::GetterError through Into::into.
  • A: The target type of the composed prism.
  • P2: The type of the second prism to compose with.
§Parameters
  • other: The prism to compose with.
§Returns

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

§Note

This method uses Into::into to convert the errors from both prisms into the common error type E. If you need custom error mapping, consider using compose_with_prism_with_mappers.

Source

pub fn compose_with_prism_with_mappers<E, A, P2: Prism<I, A>>( self, other: PrismImpl<I, A, P2>, error_mapper_1: fn(FI1::GetterError) -> E, error_mapper_2: fn(P2::GetterError) -> E, ) -> PrismImpl<S, A, impl Prism<S, A, GetterError = E>>

Composes this FallibleIsoImpl<S,I> with another PrismImpl<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 either prism fails to match, the composition will fail.

§Type Parameters
  • E: The common error type for the composed prism.
  • A: The target type of the composed prism.
§Parameters
  • other: The second prism to compose with.
  • error_mapper1: A function to map FI1::GetterError into E.
  • error_mapper2: A function to map P2::GetterError into E.
§Returns

A new PrismImpl that represents the composition of self and other with custom error mapping.

§Note

This method is similar to compose_with_prism, but provides the ability to specify custom functions to map the errors from each prism into a common error type.

Source

pub fn compose_with_lens<A, L2: Lens<I, A>>( self, other: LensImpl<I, A, L2>, ) -> PrismImpl<S, A, impl Prism<S, A, GetterError = FI1::GetterError>>

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

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

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

A new PrismImpl that represents the composition of self and other

Source

pub fn compose_with_fallible_iso<GE, RE, A, FI2: FallibleIso<I, A>>( self, other: FallibleIsoImpl<I, A, FI2>, ) -> FallibleIsoImpl<S, A, impl FallibleIso<S, A, GetterError = GE, ReverseError = RE>>
where GE: From<FI1::GetterError> + From<FI2::GetterError>, RE: From<FI1::ReverseError> + From<FI2::ReverseError>,

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

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

§Type Parameters
  • E: The error type for the composed fallible iso, which must should be able to be constructed from both FI1::GetterError and FI2::GetterError through Into::into.
  • A: The target type of the composed prism.
  • FI2: The type of the fallible iso to compose with.
§Parameters
  • other: The second Fallible Iso to compose with.
§Returns

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

§Note

This method uses Into::into to convert the errors from both prisms into the common error type E. If you need custom error mapping, consider using compose_with_fallible_iso_with_mappers.

Source

pub fn compose_with_fallible_iso_with_mappers<GE, RE, A, FI2: FallibleIso<I, A>>( self, other: FallibleIsoImpl<I, A, FI2>, getter_error_mapper_1: fn(FI1::GetterError) -> GE, getter_error_mapper_2: fn(FI2::GetterError) -> GE, reverse_error_mapper_1: fn(FI1::ReverseError) -> RE, reverse_error_mapper_2: fn(FI2::ReverseError) -> RE, ) -> FallibleIsoImpl<S, A, impl FallibleIso<S, A, GetterError = GE, ReverseError = RE>>

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

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

§Type Parameters
  • E: The common error type for the composed fallible iso.
  • 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.
  • getter_error_mapper_1: A function to map FI1::GetterError into E.
  • getter_error_mapper_2: A function to map FI2::GetterError into E.
  • reverse_error_mapper_1: A function to map FI1::ReverseError into E.
  • reverse_error_mapper_2: A function to map FI2::ReverseError into E.
§Returns

A new FallibleIsoImpl that represents the composition of self and other with custom error mapping.

§Note

This method is similar to compose_with_fallible_iso, but provides the ability to specify custom functions to map the errors from each prism into a common error type.

Source

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

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

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

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

A new FallibleIsoImpl that represents the composition of self and other

Trait Implementations§

Source§

impl<S, A, FI: FallibleIso<S, A>> From<FI> for FallibleIsoImpl<S, A, FI>

Source§

fn from(value: FI) -> Self

Converts to this type from the input type.
Source§

impl<S, A, FI: FallibleIso<S, A>> HasGetter<S, A> for FallibleIsoImpl<S, A, FI>

Source§

type GetterError = <FI as HasGetter<S, A>>::GetterError

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, FI: FallibleIso<S, A>> HasReverseGet<S, A> for FallibleIsoImpl<S, A, FI>

Source§

type ReverseError = <FI as HasReverseGet<S, A>>::ReverseError

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, FI: FallibleIso<S, A>> HasSetter<S, A> for FallibleIsoImpl<S, A, FI>

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, FI> Freeze for FallibleIsoImpl<S, A, FI>
where FI: Freeze,

§

impl<S, A, FI> RefUnwindSafe for FallibleIsoImpl<S, A, FI>

§

impl<S, A, FI> Send for FallibleIsoImpl<S, A, FI>
where FI: Send, S: Send, A: Send,

§

impl<S, A, FI> Sync for FallibleIsoImpl<S, A, FI>
where FI: Sync, S: Sync, A: Sync,

§

impl<S, A, FI> Unpin for FallibleIsoImpl<S, A, FI>
where FI: Unpin, S: Unpin, A: Unpin,

§

impl<S, A, FI> UnwindSafe for FallibleIsoImpl<S, A, FI>
where FI: 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>,