pub trait Filterable {
// Required method
fn get(&self, key: &str) -> FilterValue<'_>;
}Expand description
A trait for types which can be filtered by the filter system.
Types which implement this trait can be filtered through the use of filter DSL expressions. A filter expression might look something like the following:
repo.public && !repo.fork && repo.name in ["git-tool", "grey"]In this case, the Filter would call Filterable::get
with the property keys it intends to retrieve, in this case: repo.public,
repo.fork, and repo.name. The Filterable implementation would
then return the appropriate FilterValue for each key.
use filt_rs::{FilterValue, Filterable};
struct Repo {
name: String,
public: bool,
fork: bool,
}
impl Filterable for Repo {
fn get(&self, key: &str) -> FilterValue<'_> {
match key {
"repo.name" => self.name.as_str().into(),
"repo.public" => self.public.into(),
"repo.fork" => self.fork.into(),
_ => FilterValue::Null,
}
}
}Required Methods§
Sourcefn get(&self, key: &str) -> FilterValue<'_>
fn get(&self, key: &str) -> FilterValue<'_>
Retrieve the value of a property key.
This method should return the value of the property key as it
pertains to the filterable object. If the key is not present,
the method should return a FilterValue::Null value.
The returned value is bound to the lifetime of &self, so
implementations may borrow directly from the object being filtered
(for example by returning FilterValue::String(Cow::Borrowed(..)),
which is what From<&str> produces) to avoid copying its data.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".