[−][src]Trait druid::Lens
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.
Required methods
pub fn with<V, F: FnOnce(&U) -> V>(&self, data: &T, f: F) -> V
[src]
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.
pub fn with_mut<V, F: FnOnce(&mut U) -> V>(&self, data: &mut T, f: F) -> V
[src]
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.
Implementors
impl<A, B, L> Lens<Arc<A>, B> for InArc<L> where
A: Clone,
B: Data,
L: Lens<A, B>,
[src]
A: Clone,
B: Data,
L: Lens<A, B>,
pub fn with<V, F: FnOnce(&B) -> V>(&self, data: &Arc<A>, f: F) -> V
[src]
pub fn with_mut<V, F: FnOnce(&mut B) -> V>(&self, data: &mut Arc<A>, f: F) -> V
[src]
impl<A, B: Clone> Lens<A, B> for Constant<B>
[src]
pub fn with<V, F: FnOnce(&B) -> V>(&self, _: &A, f: F) -> V
[src]
pub fn with_mut<V, F: FnOnce(&mut B) -> V>(&self, _: &mut A, f: F) -> V
[src]
impl<A: ?Sized> Lens<A, A> for Identity
[src]
pub fn with<V, F: FnOnce(&A) -> V>(&self, data: &A, f: F) -> V
[src]
pub fn with_mut<V, F: FnOnce(&mut A) -> V>(&self, data: &mut A, f: F) -> V
[src]
impl<A: ?Sized, B, Get, Put> Lens<A, B> for Map<Get, Put> where
Get: Fn(&A) -> B,
Put: Fn(&mut A, B),
[src]
Get: Fn(&A) -> B,
Put: Fn(&mut A, B),
pub fn with<V, F: FnOnce(&B) -> V>(&self, data: &A, f: F) -> V
[src]
pub fn with_mut<V, F: FnOnce(&mut B) -> V>(&self, data: &mut A, f: F) -> V
[src]
impl<T> Lens<T, ()> for Unit
[src]
pub fn with<V, F: FnOnce(&()) -> V>(&self, _data: &T, f: F) -> V
[src]
pub fn with_mut<V, F: FnOnce(&mut ()) -> V>(&self, _data: &mut T, f: F) -> V
[src]
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>,
[src]
A: ?Sized,
B: ?Sized,
C: ?Sized,
T: Lens<A, B>,
U: Lens<B, C>,
pub fn with<V, F: FnOnce(&C) -> V>(&self, data: &A, f: F) -> V
[src]
pub fn with_mut<V, F: FnOnce(&mut C) -> V>(&self, data: &mut A, f: F) -> V
[src]
impl<T, U, Get, GetMut> Lens<T, U> for Field<Get, GetMut> where
T: ?Sized,
U: ?Sized,
Get: Fn(&T) -> &U,
GetMut: Fn(&mut T) -> &mut U,
[src]
T: ?Sized,
U: ?Sized,
Get: Fn(&T) -> &U,
GetMut: Fn(&mut T) -> &mut U,
pub fn with<V, F: FnOnce(&U) -> V>(&self, data: &T, f: F) -> V
[src]
pub fn with_mut<V, F: FnOnce(&mut U) -> V>(&self, data: &mut T, f: F) -> V
[src]
impl<T: ?Sized> Lens<T, <T as Deref>::Target> for Deref where
T: Deref + DerefMut,
[src]
T: Deref + DerefMut,
pub fn with<V, F: FnOnce(&T::Target) -> V>(&self, data: &T, f: F) -> V
[src]
pub fn with_mut<V, F: FnOnce(&mut T::Target) -> V>(
&self,
data: &mut T,
f: F
) -> V
[src]
&self,
data: &mut T,
f: F
) -> V
impl<T: ?Sized, I> Lens<T, <T as Index<I>>::Output> for Index<I> where
T: Index<I> + IndexMut<I>,
I: Clone,
[src]
T: Index<I> + IndexMut<I>,
I: Clone,
pub fn with<V, F: FnOnce(&T::Output) -> V>(&self, data: &T, f: F) -> V
[src]
pub fn with_mut<V, F: FnOnce(&mut T::Output) -> V>(
&self,
data: &mut T,
f: F
) -> V
[src]
&self,
data: &mut T,
f: F
) -> V
impl<T: ?Sized, U: ?Sized> Lens<T, U> for Ref where
T: AsRef<U> + AsMut<U>,
[src]
T: AsRef<U> + AsMut<U>,