-
-
Notifications
You must be signed in to change notification settings - Fork 325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Add expression macro for the selector type #1544
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1544 +/- ##
=====================================
Coverage 75.7% 75.7%
=====================================
Files 79 79
Lines 7252 7252
=====================================
Hits 5487 5487
Misses 1765 1765
|
Signed-off-by: Danil-Grigorev <[email protected]>
e824f9a
to
8170848
Compare
Probably unpopular opinion, but doesn't this end up making users learn yet another foreign syntax of specifying labels? Right now there are already so many different syntaxes (kubectl CLI, LabelSelector matchLabels, LabelSelector matchExpressions), and we are adding yet another syntax here. If the sole intention is to avoid the pub struct In<KeyT, ValuesT>(KeyT, ValuesT);
impl<KeyT, ValuesT> From<In<KeyT, ValuesT>> for Expression
where
KeyT: Into<String>,
ValuesT: IntoIterator,
<ValuesT as IntoIterator>::Item: Into<String>,
{ ... }
// vice versa for the other three variants
impl<T: Into<Expression>> From<T> for Selector { ... }
impl<T1, T2> From<(T1, T2)> for Selector
where
T1: Into<Expression>,
T2: Into<Expression>,
{ ... } Then users can simply write let selector: labels::Selector = (
labels::In("foo", ["bar"]),
labels::Equal("baz", "qux"),
).into(); |
I have the same reservations as @SOF3 here (even though I did ask for this). I think it because is becoming more of a DSL than a typed convenience, when the primary aim is to get rid of all the if the macro was a little more typed ala: +selector::in!("foo", ["bar", "baz"]);
-expression!("foo" in "bar", "baz"); then i'd be less concerned. though, if SOF3's solution without macros work:
then that ^ might be a better approach than macros. |
Yeah, I'm also seeing that this is the limit of macro usage, like selector! is not working for me with the current model. The idea was to give it a feel like writing a raw string (as before), but with typing: selector!("foo" in ("bar", "baz"),"env" == "dev"); Macros are not giving readable compiler errors and I have the same feeling of a new DSL. Plus you can't easily track in which branch your expression ended up. Was a good exercise though 🙂 |
Closing this to revise later. |
Motivation
This is a follow-up on #1539 which adds a macro for
Expression
type, allowing to avoid unnecessary amount ofinto()
calls while constructing a simple static expression.Solution
Example:
To be done:
selector!
macro (can be done?..)