Skip to main content

Filter

Trait Filter 

Source
pub trait Filter<M>: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn label(&self) -> Text;
    fn to_expr(&self, cx: &Cx, value: &FilterValue) -> Option<Expr<bool>>;
    fn control<'a>(
        &self,
        cx: &'a Cx,
        input: FilterInput,
    ) -> Pin<Box<dyn View + 'a>>;

    // Provided methods
    fn is_noop_value(&self, _value: &FilterValue) -> bool { ... }
    fn load_control<'s, 'a>(
        &'s self,
        cx: &'a Cx,
        input: FilterInput,
    ) -> Pin<Box<dyn Future<Output = Pin<Box<dyn View + 'a>>> + Send + 's>>
       where 'a: 's { ... }
    fn reads(&self) -> Option<Reads<M>> { ... }
}
Expand description

One table filter declares a control and its predicate.

struct Adults;

impl Filter<User> for Adults {
    fn name(&self) -> &str {
        "adults"
    }
    fn label(&self) -> Text {
        "Adults".into()
    }
    fn to_expr(&self, _cx: &Cx, value: &FilterValue) -> Option<Expr<bool>> {
        (value.single() == Some("yes")).then(|| User::fields().age().ge(18))
    }
    fn control<'a>(&self, cx: &'a Cx, input: FilterInput) -> BoxView<'a> {
        input.select(cx, vec![("yes".into(), "Adults only".into())])
    }
}

Required Methods§

Source

fn name(&self) -> &str

The filter’s identifier, distinct within its table.

Source

fn label(&self) -> Text

The label the control renders beside it.

Source

fn to_expr(&self, cx: &Cx, value: &FilterValue) -> Option<Expr<bool>>

The predicate value selects for the request cx, or None when it selects none. The table warns about a value that selects none unless is_noop_value accepts it.

Source

fn control<'a>(&self, cx: &'a Cx, input: FilterInput) -> Pin<Box<dyn View + 'a>>

The control in the table’s filter menu.

Provided Methods§

Source

fn is_noop_value(&self, _value: &FilterValue) -> bool

Whether value selects no predicate without being invalid.

Source

fn load_control<'s, 'a>( &'s self, cx: &'a Cx, input: FilterInput, ) -> Pin<Box<dyn Future<Output = Pin<Box<dyn View + 'a>>> + Send + 's>>
where 'a: 's,

The control in the filter menu once what it offers has loaded, such as rows a query returns. The filter menu renders this one; it defaults to control.

Source

fn reads(&self) -> Option<Reads<M>>

The fields of the record to_expr filters by, or None when the filter does not say.

A panel drops a filter reading a field field_access hides from the user, and refuses to mount a resource restricting a field whose filters answer None. The built-in filters answer their own field.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl<M> Filter<M> for DateFilter<M>
where M: Model + Send + Sync,

Source§

impl<M> Filter<M> for NumberFilter<M>
where M: Model + Send + Sync,

Source§

impl<M> Filter<M> for PresenceFilter<M>
where M: Model + Send + Sync,

Source§

impl<M> Filter<M> for QueryFilter<M>
where M: Model + Send + Sync,

Source§

impl<M> Filter<M> for SelectFilter<M>
where M: Model + Send + Sync,

Source§

impl<M> Filter<M> for TernaryFilter<M>
where M: Model + Send + Sync,

Source§

impl<M> Filter<M> for TextFilter<M>
where M: Model + Send + Sync,