FallibleIso

Trait FallibleIso 

Source
pub trait FallibleIso<S, A>:
    HasGetter<S, A>
    + HasSetter<S, A>
    + HasReverseGet<S, A> { }
Expand description

A FallibleIso defines a reversible, but potentially failing conversion between two types.

It provides:

  • try_get to convert a value of type S to type A, possibly failing with an error of type GetterError
  • set to change the value the optic operates on
  • try_reverse_get to convert a value of type A to type S, possibly failing with an error of type ReverseError

This is useful when working with a data structure that can be represented in two different ways, but conversion between the two types might fail, such as a String and an IpAddress

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

  • [Iso] — a variant of FallibleIso where the mapping cannot fail.
  • FallibleIsoImpl — the wrapper of opaque struct that implement the FallibleIso trait

Implementors§

Source§

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