pub struct OperatorSetWithContext<R, A> { /* private fields */ }
filter
only.Expand description
A collection of filters for a type that requires a context object.
An OperatorSetWithContext
can be created for any type which
implements FilterableWithContext
. Its constructor supplies a
visitor to the type’s Meta
type, and constructs the necessary
FilterClass
objects. It can be used directly to convert
incoming query pairs from Django-style query URLs into appropriate
Filter
objects.
Note that the context object provided on construction may be
stored within the resulting object, and may also be cloned into
the Meta
for other types.
Implementations§
Source§impl<'a, A: Clone + 'a, R: FilterableWithContext<'a, A>> OperatorSetWithContext<R, A>
impl<'a, A: Clone + 'a, R: FilterableWithContext<'a, A>> OperatorSetWithContext<R, A>
Sourcepub fn new(access: A) -> Self
pub fn new(access: A) -> Self
Create a new OperatorSetWithContext
, using the Meta
record
from the target type, which will be initialized from the provided
context object access
.
Sourcepub fn create_filter(
&self,
field: &str,
operator: Option<&str>,
rhs: &str,
) -> Result<Box<dyn Filter<R> + 'a>, FilterError>
pub fn create_filter( &self, field: &str, operator: Option<&str>, rhs: &str, ) -> Result<Box<dyn Filter<R> + 'a>, FilterError>
Create a new filter from a decomposed URL. Note that the
decomposition is ambiguous, so
create_filter_from_query_pair
is often preferable. The ambiguity arises because there may be
no operator part, and the field part may have arbitrarily many
parts. Since everything is separated with double underscores
there is no way without additional information to distinguish
an expression with an explicit operator from an expression on
a nested field with an implicit operator. Here - field
is
the field specification part of the string, including any
nested fields. - operator
is the operator specification, if
any. - rhs
is the argument part, after the =
in the URL
section.
Sourcepub fn create_filter_from_query_pair(
&self,
lhs: &str,
rhs: &str,
) -> Result<Box<dyn Filter<R> + 'a>, FilterError>
pub fn create_filter_from_query_pair( &self, lhs: &str, rhs: &str, ) -> Result<Box<dyn Filter<R> + 'a>, FilterError>
Create a new filter from a fragment of query URL. The expected
input is a lhs=rhs
pair from a query string, with lhs
and
rhs
given separately. The output will either be an error, or
a Filter
which can apply the specified test to objects of
the target type, returning either true
(include) or false
(exclude).
Sourcepub fn create_filter_from_query(
&self,
expr: &str,
) -> Result<Box<dyn Filter<R> + 'a>, FilterError>
pub fn create_filter_from_query( &self, expr: &str, ) -> Result<Box<dyn Filter<R> + 'a>, FilterError>
Create a new filter from a fragment of query URL. The expected
input is a lhs=rhs
pair from a query string, with lhs
and
rhs
given together in a single string. The output will
either be an error, or a Filter
which can apply the
specified test to objects of the target type, returning
either true
(include) or false
(exclude).