Skip to main content

Selector

Trait Selector 

Source
pub trait Selector<S: AppState> {
    type Output;

    // Required method
    fn select(view: &View<'_, S>) -> Self::Output;
}
Expand description

A selector that derives a value from the View.

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: &View<MyState>) -> usize {
        view.state.items.len()
    }
}

// In a widget:
let count: usize = view.select::<ItemCount>();

Required Associated Types§

Source

type Output

The type produced by the selector.

Required Methods§

Source

fn select(view: &View<'_, S>) -> Self::Output

Extract the value from the given view.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§