GetterImpl

Struct GetterImpl 

Source
pub struct GetterImpl<S, A, G: Getter<S, A>>(pub G, _);
Expand description

A wrapper of the Getter optic implementations, encapsulating a total getter function.

GetterImpl provides a way to define total getters - optics that retrieve a value of type A from a source of type S. This struct is particularly useful in scenarios where you need to compose or reuse getter logic that always succeeds.

§Note

This struct is not intended to be created by users directly, but it implements a From<Getter<S,A>> so that implementors of new optic types can wrap their concrete implementation of a Getter 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

  • Getter trait for defining custom partial getters.
  • [mapped_getter] function for creating GetterImpl instances from mapping functions.

Tuple Fields§

§0: G

Implementations§

Source§

impl<S, I, G1: Getter<S, I>> GetterImpl<S, I, G1>

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 GetterImpl<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 GetterImpl<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>>
where G1: Setter<S, I>,

Composes this GetterImpl<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<A, P2: Prism<I, A>>( self, other: PrismImpl<I, A, P2>, ) -> PartialGetterImpl<S, A, impl PartialGetter<S, A, GetterError = P2::GetterError>>

Composes this GetterImpl<S,I> with a Prism<I,A>, resulting in a new PartialGetterImpl<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 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 PartialGetterImpl 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>, ) -> GetterImpl<S, A, impl Getter<S, A>>

Composes this GetterImpl<S,I> with a LensImpl<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 lens.
  • L2: The type of the lens to compose with.
§Parameters
  • other: The lens to compose with.
§Returns

A new GetterImpl 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>, ) -> PartialGetterImpl<S, A, impl PartialGetter<S, A, GetterError = FI2::GetterError>>

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

The resulting PartialGetterImpl 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 PartialGetterImpl 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>, ) -> GetterImpl<S, A, impl Getter<S, A>>

Composes this GetterImpl<S,I> with an IsoImpl<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 lens.
  • ISO2: The type of the lens to compose with.
§Parameters
  • other: The iso to compose with.
§Returns

A new GetterImpl that represents the composition of self and other

Trait Implementations§

Source§

impl<S, A, G: Getter<S, A>> From<G> for GetterImpl<S, A, G>

Source§

fn from(value: G) -> Self

Converts to this type from the input type.
Source§

impl<S, A, G: Getter<S, A>> HasGetter<S, A> for GetterImpl<S, A, G>

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

Auto Trait Implementations§

§

impl<S, A, G> Freeze for GetterImpl<S, A, G>
where G: Freeze,

§

impl<S, A, G> RefUnwindSafe for GetterImpl<S, A, G>

§

impl<S, A, G> Send for GetterImpl<S, A, G>
where G: Send, S: Send, A: Send,

§

impl<S, A, G> Sync for GetterImpl<S, A, G>
where G: Sync, S: Sync, A: Sync,

§

impl<S, A, G> Unpin for GetterImpl<S, A, G>
where G: Unpin, S: Unpin, A: Unpin,

§

impl<S, A, G> UnwindSafe for GetterImpl<S, A, G>
where G: 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> 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<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, G> Getter<S, A> for G
where G: HasGetter<S, A, GetterError = Infallible>,

Source§

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