Iso

Trait Iso 

Source
pub trait Iso<S, A>:
    HasGetter<S, A, GetterError = Infallible>
    + HasSetter<S, A>
    + HasReverseGet<S, A, ReverseError = Infallible> { }
Expand description

An Iso defines an isomorphism between two type, which is a bijective, reversible conversion between the members of two types.

It provides:

  • get to convert a value of type S to type A
  • set to change the value the optic operates on
  • reverse_get to convert a value of type A to type S

This is useful when working with a data structure that can be represented in two different ways, such as a Point in XY coordinates and polar coordinates.

Type Arguments

  • S: The data type the optic operates on
  • A: The data type the optic focuses on

§Note

This is a marker trait that is blanket implemented for all structs that satisfy the requirements.

§See Also

  • [FallibleIso] — a variant of Iso where the mapping might fail, returning an error
  • IsoImpl — the wrapper of opaque struct that implement the Iso trait

Implementors§

Source§

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