pub trait Lens:
'static
+ Copy
+ Debug {
type Source;
type Target;
// Required method
fn view<'a>(
&self,
source: &'a Self::Source,
) -> Option<LensValue<'a, Self::Target>>;
// Provided method
fn id(&self) -> StoreId { ... }
}
Expand description
A Lens allows the construction of a reference to a piece of some data, e.g. a field of a struct.
When deriving the Lens
trait on a struct, the derive macro constructs a static type which implements the Lens
trait for each field.
The view()
method takes a reference to the struct type as input and outputs a reference to the field.
This provides a way to specify a binding to a specific field of some application data.
Required Associated Types§
Required Methods§
Provided 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.