Replies: 1 comment 1 reply
-
I don't think it should be the responsibility of PCR to provide a // Assuming they're all Option<bool> args
let arg1 = Some(true);
let arg2 = Some(false);
let arg3 = None as Option<bool>;
// If each arg was an enum you could put all of them in a Vec and filter_map to turn each
// variant into an Option<WhereParam>
let arg1 = arg1.unwrap_or(false).then(|| not![model::arg1::equals(None));
let arg2 = arg2.unwrap_or(false).then(|| not![model::arg2::equals(None));
let arg3 = arg3.unwrap_or(false).then(|| not![model::arg3::equals(None));
client
.model()
// Will filter out any None values and use the value inside Some(..)
.find_many(vec![arg1, arg2, arg3].into_iter().filter_map(|a| a).collect())
.exec()
.await; Thinking about it more, |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Note: I encountered this in the same code as #114
Sometimes filters are optional. In my code, I had an argument of type
Option<bool>
. If the argument isNone
orSome(false)
, I don't need to filter. If it'sSome(true)
, I need to apply a specific filter. Here is how it looks:It's kinda fine here. The real problem will occur when there are two such arguments, because I'll need to combine all possible cases, eg
None, None
,None, Some(true)
,None, Some(false)
and six more. Of course, I could forOption<bool>
I could use.unwrap_or(false)
and save myself some headache. But the problem persists.What will solve this is the
WhereParam::None
variant (name may be different). This variant will be just ignored by the filter system. The snippet could look like this:In case there are more arguments, they can be passed as another members of vec.
Beta Was this translation helpful? Give feedback.
All reactions