HasOver

Trait HasOver 

Source
pub trait HasOver<S, A> {
    // Required method
    fn over<F>(&self, source: &mut S, f: F)
       where F: Fn(A) -> A;
}
Expand description

Provides a convenient interface for applying a transformation function over a target value within a source.

This trait is automatically implemented for any optic that implements HasGetter and HasSetter.

§Example

use optics::{Lens, HasOver, mapped_prism, mapped_lens};

struct Point {
    x: u32,
    y: u32,
}

let x_lens = mapped_lens(
    |p: &Point| p.x,
    |p: &mut Point, x| { p.x = x },
);

let mut point = Point { x: 10, y: 20 };
x_lens.over(&mut point, |x| x + 5);
assert_eq!(point.x, 15);

§See also:

Required Methods§

Source

fn over<F>(&self, source: &mut S, f: F)
where F: Fn(A) -> A,

Retrieves a value of type A from a source of type S.

§Parameters
  • source: A reference to the source of type S from which the value is to be retrieved.
§Returns

Returns the value of type A that the optic focuses on.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<S, A, T> HasOver<S, A> for T
where T: HasGetter<S, A> + HasSetter<S, A>,