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§
Sourcefn to_expr(&self, cx: &Cx, value: &FilterValue) -> Option<Expr<bool>>
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.
Sourcefn control<'a>(&self, cx: &'a Cx, input: FilterInput) -> Pin<Box<dyn View + 'a>>
fn control<'a>(&self, cx: &'a Cx, input: FilterInput) -> Pin<Box<dyn View + 'a>>
The control in the table’s filter menu.
Provided Methods§
Sourcefn is_noop_value(&self, _value: &FilterValue) -> bool
fn is_noop_value(&self, _value: &FilterValue) -> bool
Whether value selects no predicate without being invalid.
Sourcefn 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 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.
Sourcefn reads(&self) -> Option<Reads<M>>
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".