Prism

Trait Prism 

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

A Prism is an optic that focuses on a potentially missing value, such as a variant of a sum type (enum).

It provides:

  • try_get to optionally extract a focus value from a larger type
  • set to set the focused value of a larger type

This is useful for working with enum variants, Option values, or other sum types where a focus value might be absent.

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

  • [Getter] — an optic that focuses on a potentially missing value in a larger type
  • [Setter] — an optic that can change its focused value
  • [Lens] — an optic that focuses on an always-present value in a product type (e.g., a required struct field)
  • [FallibleIso] — a variant of Iso where the mapping might fail, returning an error
  • [Iso] — an isomorphism optic representing a reversible bijective conversion between two types

Implementors§

Source§

impl<S, A, P: HasGetter<S, A> + HasSetter<S, A>> Prism<S, A> for P