Expand description
A lens is a datatype that gives access to a part of a larger
data structure.
A simple example of a lens is a field of a struct; in this case,
the lens itself is zero-sized. Another case is accessing an array
element, in which case the lens contains the array index.
Many Lens
implementations will be derived by macro, but custom
implementations are practical as well.
The name “lens” is inspired by the Haskell lens package, which
has generally similar goals. It’s likely we’ll develop more
sophistication, for example combinators to combine lenses.
Get non-mut access to the field.
Runs the supplied closure with a reference to the data. It’s
structured this way, as opposed to simply returning a reference,
so that the data might be synthesized on-the-fly by the lens.
Get mutable access to the field.
This method is defined in terms of a closure, rather than simply
yielding a mutable reference, because it is intended to be used
with value-type data (also known as immutable data structures).
For example, a lens for an immutable list might be implemented by
cloning the list, giving the closure mutable access to the clone,
then updating the reference after the closure returns.
impl<A, L0, L1, L0B, L1B> Lens<A, (L0B, L1B)> for (L0, L1) where
L0B: Clone,
L1B: Clone,
L0: Lens<A, L0B>,
L1: Lens<A, L1B>,
impl<A, L0, L1, L2, L0B, L1B, L2B> Lens<A, (L0B, L1B, L2B)> for (L0, L1, L2) where
L0B: Clone,
L1B: Clone,
L2B: Clone,
L0: Lens<A, L0B>,
L1: Lens<A, L1B>,
L2: Lens<A, L2B>,
impl<A, L0, L1, L2, L3, L0B, L1B, L2B, L3B> Lens<A, (L0B, L1B, L2B, L3B)> for (L0, L1, L2, L3) where
L0B: Clone,
L1B: Clone,
L2B: Clone,
L3B: Clone,
L0: Lens<A, L0B>,
L1: Lens<A, L1B>,
L2: Lens<A, L2B>,
L3: Lens<A, L3B>,
impl<A, L0, L1, L2, L3, L4, L0B, L1B, L2B, L3B, L4B> Lens<A, (L0B, L1B, L2B, L3B, L4B)> for (L0, L1, L2, L3, L4) where
L0B: Clone,
L1B: Clone,
L2B: Clone,
L3B: Clone,
L4B: Clone,
L0: Lens<A, L0B>,
L1: Lens<A, L1B>,
L2: Lens<A, L2B>,
L3: Lens<A, L3B>,
L4: Lens<A, L4B>,
impl<A, L0, L1, L2, L3, L4, L5, L0B, L1B, L2B, L3B, L4B, L5B> Lens<A, (L0B, L1B, L2B, L3B, L4B, L5B)> for (L0, L1, L2, L3, L4, L5) where
L0B: Clone,
L1B: Clone,
L2B: Clone,
L3B: Clone,
L4B: Clone,
L5B: Clone,
L0: Lens<A, L0B>,
L1: Lens<A, L1B>,
L2: Lens<A, L2B>,
L3: Lens<A, L3B>,
L4: Lens<A, L4B>,
L5: Lens<A, L5B>,
impl<A, L0, L1, L2, L3, L4, L5, L6, L0B, L1B, L2B, L3B, L4B, L5B, L6B> Lens<A, (L0B, L1B, L2B, L3B, L4B, L5B, L6B)> for (L0, L1, L2, L3, L4, L5, L6) where
L0B: Clone,
L1B: Clone,
L2B: Clone,
L3B: Clone,
L4B: Clone,
L5B: Clone,
L6B: Clone,
L0: Lens<A, L0B>,
L1: Lens<A, L1B>,
L2: Lens<A, L2B>,
L3: Lens<A, L3B>,
L4: Lens<A, L4B>,
L5: Lens<A, L5B>,
L6: Lens<A, L6B>,
impl<A, L0, L1, L2, L3, L4, L5, L6, L7, L0B, L1B, L2B, L3B, L4B, L5B, L6B, L7B> Lens<A, (L0B, L1B, L2B, L3B, L4B, L5B, L6B, L7B)> for (L0, L1, L2, L3, L4, L5, L6, L7) where
L0B: Clone,
L1B: Clone,
L2B: Clone,
L3B: Clone,
L4B: Clone,
L5B: Clone,
L6B: Clone,
L7B: Clone,
L0: Lens<A, L0B>,
L1: Lens<A, L1B>,
L2: Lens<A, L2B>,
L3: Lens<A, L3B>,
L4: Lens<A, L4B>,
L5: Lens<A, L5B>,
L6: Lens<A, L6B>,
L7: Lens<A, L7B>,
impl<T, U, A, B, C> Lens<A, C> for Then<T, U, B> where
A: ?Sized,
B: ?Sized,
C: ?Sized,
T: Lens<A, B>,
U: Lens<B, C>,