I have the following situation:
pub enum FilterOp<T: Into<FieldValue> = ()> {
// binary operators
EQUAL(T),
LESS_THAN(T),
...
// unary operators
IS_NULL,
...
}
My goal is to use the same enum for both binary operators, which carry an additional value of T
, and unary operators, which don't. When I use a "unary operator" variant (eg FilterOp::IS_NULL
), I want T
to be ()
.
However, I want to use this enum with this trait:
pub trait Filter<T: Into<FieldValue> = ()> {
fn filter(self, field: &str, op: FilterOp<T>) -> Self;
...
}
Which means, when I implement Filter
like this:
impl<T: Into<FieldValue>> Filter<T> for Query {
fn filter(self, field: &str, op: FilterOp<T>) -> Self {
...
}
...
}
And use Query::filter
with FilterOp::IS_NULL
:
database().query().filter("test_null", FilterOp::IS_NULL)
The type for T
in impl<T: Into<FieldValue>> Filter<T> for Query
which implements filter
cannot be determined:
error[E0283]: type annotations required: cannot resolve `_: std::convert::Into<document::fields::FieldValue>`
--> database/src/firestore/query.rs:180:32
|
180 | ... .filter("test_null", FilterOp::IS_NULL);
| ^^^^^^
Which is why I have to use this syntax:
database().query().filter("test_null", FilterOp::<()>::IS_NULL)
Why doesn't filter
use the default for T
in the declaration of FilterOp
here? Shouldn't FilterOp::IS_NULL
be of type FilterOp::<()>
when T
is not specified? What could I do to be able to omit the type annotation?
Thanks for your help