Skip to main content

RefLens

Trait RefLens 

Source
pub trait RefLens: Lens {
    // Required method
    fn get_ref<'a>(&self, source: &'a Self::Source) -> &'a Self::Target;

    // Provided methods
    fn mutate_with_fn(
        &self,
        source: &mut Self::Source,
        f: &dyn Fn(&Self::Target) -> Self::Target,
    ) { ... }
    fn modify(
        &self,
        source: Self::Source,
        f: &dyn Fn(&Self::Target) -> Self::Target,
    ) -> Self::Source { ... }
}
Expand description

A lens that allows the target to be accessed and mutated by reference.

Required Methods§

Source

fn get_ref<'a>(&self, source: &'a Self::Source) -> &'a Self::Target

Gets a reference to the target of the lens. (This does not consume the source.)

Provided Methods§

Source

fn mutate_with_fn( &self, source: &mut Self::Source, f: &dyn Fn(&Self::Target) -> Self::Target, )

Modifies the target of the lens by applying a function to the current value.

Source

fn modify( &self, source: Self::Source, f: &dyn Fn(&Self::Target) -> Self::Target, ) -> Self::Source

Modifies the target of the lens by applying a function to the current value. This consumes the source.

Implementations on Foreign Types§

Source§

impl<L: RefLens + ?Sized> RefLens for Box<L>

Source§

fn get_ref<'a>(&self, source: &'a L::Source) -> &'a L::Target

Implementors§

Source§

impl<LHS, RHS> RefLens for ComposedLens<LHS, RHS>
where LHS: RefLens, LHS::Target: 'static, RHS: RefLens<Source = LHS::Target>,

Source§

impl<T> RefLens for VecLens<T>