pub trait Lens<S, A>: HasGetter<S, A, GetterError = Infallible> + HasSetter<S, A> { }Expand description
An optic for focusing on a value that is guaranteed to exist within a larger structure.
A Lens is appropriate for product types (e.g., structs) where the focus is always present.
Unlike a [Prism], a Lens cannot fail to retrieve its focus — hence its associated
[Optic::Error] type is fixed to Infallible.
It can also act as a [Prism] for compatibility in compositions.
§See Also
- [
Optic] — base trait implemented by all optics - [
Prism] — optional focus optic for sum types - [
Iso] — reversible transformations - [
FallibleIso] — reversible transformations with fallible forward mapping
A Lens is an optic that focuses on a value that is guaranteed to exist within a larger structure.
A Lens is appropriate for product types (e.g., structs) where the focus is always present.
Unlike a [Prism], a Lens cannot fail to retrieve its focus — hence its associated
[Getter::GetterError] type is fixed to Infallible.
It provides:
getto extract a focused value from a larger typesetto set the focused value of a larger type
Type Arguments
S: The data type the optic operates onA: 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 value that is guaranteed to exist in a larger type - [
Setter] — an optic that can change its focused value - [
Iso] — an isomorphism optic representing a reversible bijective conversion between two types