pub struct LensImpl<S, A, L: Lens<S, A>>(pub L, _);Expand description
A wrapper of the Lens optic implementations, encapsulating a getter and setter function.
LensImpl provides a way to define lenses - optics that can retrieve and change a value of
type A inside a source of type S,
They are particularly useful in scenarios where you need to focus on a field of a struct.
§Note
This struct is not intended to be created by users directly, but it implements a From<PartialGetter<S,A>> so
that implementors of new optic types can wrap their concrete implementation of a PartialGetter optic.
§Type Parameters
S: The source type from which the value is to be retrieved.A: The target type of the value to be retrieved.
§See Also
Lenstrait for defining custom partial getters.- [
mapped_lens] function for creatingLebsImplinstances from mapping functions.
Tuple Fields§
§0: LImplementations§
Source§impl<S, I, L: Lens<S, I>> LensImpl<S, I, L>
impl<S, I, L: Lens<S, I>> LensImpl<S, I, L>
Sourcepub 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>>
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 LensImpl<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.
Sourcepub fn compose_with_getter<A, G2: Getter<I, A>>(
self,
other: GetterImpl<I, A, G2>,
) -> GetterImpl<S, A, impl Getter<S, A>>
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 LensImpl<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.
Sourcepub fn compose_with_setter<A, S2: Setter<I, A>>(
self,
other: SetterImpl<I, A, S2>,
) -> SetterImpl<S, A, impl Setter<S, A>>
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 LensImpl<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.
Sourcepub fn compose_with_prism<A, P: Prism<I, A>>(
self,
other: PrismImpl<I, A, P>,
) -> PrismImpl<S, A, impl Prism<S, A, GetterError = P::GetterError>>
pub fn compose_with_prism<A, P: Prism<I, A>>( self, other: PrismImpl<I, A, P>, ) -> PrismImpl<S, A, impl Prism<S, A, GetterError = P::GetterError>>
Composes this LensImpl<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 second prism to compose with.
§Parameters
other: The second prism to compose with.
§Returns
A new PrismImpl that represents the composition of self and other.
Sourcepub fn compose_with_lens<A, L2: Lens<I, A>>(
self,
other: LensImpl<I, A, L2>,
) -> LensImpl<S, A, impl Lens<S, A>>
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 LensImpl<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
Sourcepub fn compose_with_fallible_iso<A, FI2: FallibleIso<I, A>>(
self,
other: FallibleIsoImpl<I, A, FI2>,
) -> PrismImpl<S, A, impl Prism<S, A, GetterError = FI2::GetterError>>
pub fn compose_with_fallible_iso<A, FI2: FallibleIso<I, A>>( self, other: FallibleIsoImpl<I, A, FI2>, ) -> PrismImpl<S, A, impl Prism<S, A, GetterError = FI2::GetterError>>
Composes this LensImpl<S,I> with a FallibleIso<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 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 PrismImpl that represents the composition of self and other.
Sourcepub fn compose_with_iso<A, ISO2: Iso<I, A>>(
self,
other: IsoImpl<I, A, ISO2>,
) -> LensImpl<S, A, impl Lens<S, A>>
pub fn compose_with_iso<A, ISO2: Iso<I, A>>( self, other: IsoImpl<I, A, ISO2>, ) -> LensImpl<S, A, impl Lens<S, A>>
Composes this LensImpl<S,I> with an IsoImpl<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.ISO2: The type of the lens to compose with.
§Parameters
other: The iso to compose with.
§Returns
A new LensImpl that represents the composition of self and other
Trait Implementations§
Source§impl<S, A, L: Lens<S, A>> HasGetter<S, A> for LensImpl<S, A, L>
impl<S, A, L: Lens<S, A>> HasGetter<S, A> for LensImpl<S, A, L>
Source§type GetterError = Infallible
type GetterError = Infallible
Infallible for infallible optics.