-
-
Notifications
You must be signed in to change notification settings - Fork 126
✨ zv: Added a signature! macro #1536
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
base: main
Are you sure you want to change the base?
Conversation
@hadihaider055 thanks! I'll have a look later but please remember to use emoji rather than the emoji code. 😉 |
Ah sure @zeenix, I just saw this on mobile and it seems like the emoji code isn't working. Thanks for pointing it out! |
It won't work in many software (including git cli tools). That's why it's best to follow the advice in the contribution guidelines exactly. 😉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super cool. 👍 I've been meaning to do this for a while now. :) Just two things apart from the inline comments:
- It's a bit unexpected to have a non-derive macro in a crate suffixed
_derive
. I think, it possible, we should add this inzvariant_utils
and then re-export fromzvariant
. - Let's make use of this in the zvariant tests where we create signature from a static string (there are at least 3 places, I can see).
CodSpeed Performance ReportMerging #1536 will not alter performanceComparing Summary
|
Thanks for doing that. 👍 However, the macro still remains in zvariant_derive. The idea was that it doesn't belong there, so it should only be zvariant that rexports it and the whole macro (not just the impl) should be in zvariant_utils. Having said that, there are some strange rules about where macros could be and can't be, so it's possible that those rules don't allow a macro to be in zvariant_utils. If so, we'll have to live with it being in zvariant_derive (even if it's strange). You should be able to very quickly figure that out when you try to move the macro there. BTW, the PR title and commit title say "Siganture", while the macro is called "signature". |
Thanks @zeenix! You're right on moving the entire macro to Currently, zvariant_derive has For now, I think we have 2 options:
What do you think is the best approach? I believe option 1 is the most practical since most of the logic is already in
Thanks for pointing it out! I'll fix this. |
Yeah, that's what I feared. 😢
As I wrote in my previous comment, that's what we have to do then. Then there is also no need for the impl to be in _utils since that crate is mainly to keep common code between zvariant_derive and zbus_macros and zvariant API that we need in the macro code itself but can't be in zvariant_derive itself.
Yeah but we don't want the impl in _utils for the reason I mentioned. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM otherwise. Thanks so much!
We should advertise this signature a bit more. E.g the Signature
docs should recommend this macro and make use of that in its examples. Also grep for uses of Signature::try_from
and Signature::from_str
in the repo and update them. Please keep the atomic commits preference in mind, while at it. ;)
zvariant_derive/src/lib.rs
Outdated
/// Allows to create a `Signature` from a string literal at compile time, | ||
/// with validation to ensure the signature string is valid. | ||
/// | ||
/// The macro validates the signature string at compile time: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need examples here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could just be a copy of the examples in the Signature
docs itself (after you've converted them to use this macro) + a const example (just copy from the commit log).
cb7d010
to
fcf35d7
Compare
☝️ |
@zeenix, I've added the documentation with proper examples in the Signature macro and updated the Signature type docs to recommend it. Let me know if there's anything unclear for the readers. |
Implement a `signature!` macro that constructs const Signatures with compile-time validation. The macro allows creating Signature from string literals at compile time: const SIGNATURE: Signature = signature!("a{sv}"); let sig = signature!("yys"); Fixes: z-galaxy#984
@zeenix, on it! Should I separate it into 3 commits with the feature, docs, and testing? Or rather, the tests be committed with the feature commit |
Both options are fine but 3 commits would be better indeed. |
Recommendation for the signature! macro and examples about the runtime and compile-time signature creation.
Replace Signature::try_from() and Signature::from_str() calls with the new signature! macro.
@zeenix, I've split the changes into 3 commits (feature, doc, and test). Is it fine? |
Add a
signature!
macro that creates const signatures with compile-time validation. This makes it easier to work with D-Bus signatures while catching invalid ones early.Fixes #984