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§
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.