pub trait Selector<S: GlobalState> {
type Output;
// Required method
fn select(view: ViewHandle<S>) -> Self::Output;
}Expand description
A selector that derives a value from a ViewHandle.
Selectors extract and transform data from state so widgets can depend on derived values without coupling to the full state shape.
§Example
ⓘ
struct ItemCount;
impl Selector<MyState> for ItemCount {
type Output = usize;
fn select(view: ViewHandle<MyState>) -> usize {
view.state().items.len()
}
}
// In a widget:
let count: usize = view.select_with::<ItemCount>();Required Associated Types§
Required Methods§
Sourcefn select(view: ViewHandle<S>) -> Self::Output
fn select(view: ViewHandle<S>) -> Self::Output
Extract the value from the given view handle.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".