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
Use abci-tag proc_macro for event attributes #276
Use abci-tag proc_macro for event attributes #276
Conversation
Codecov ReportBase: 65.31% // Head: 65.09% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #276 +/- ##
==========================================
- Coverage 65.31% 65.09% -0.22%
==========================================
Files 125 127 +2
Lines 13210 13868 +658
==========================================
+ Hits 8628 9028 +400
- Misses 4582 4840 +258
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
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.
Thank you for this!
Could you also implement the change for
- the structs found in
core::ics02_client::events
ModuleEventAttribute
incrate::events
@@ -0,0 +1,14 @@ | |||
[package] | |||
name = "abci-tag-proc-marco" |
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.
name = "abci-tag-proc-marco" | |
name = "abci-event-attr-key-proc-macro" |
use syn::{parse_macro_input, DataStruct, DeriveInput, Ident as SynIdent}; | ||
|
||
#[proc_macro_attribute] | ||
pub fn abci_tag(args: TokenStream, item: TokenStream) -> TokenStream { |
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.
pub fn abci_tag(args: TokenStream, item: TokenStream) -> TokenStream { | |
pub fn abci_event_attr_key(args: TokenStream, item: TokenStream) -> TokenStream { |
Could please change the name? I find this more descriptive.
EventAttribute { | ||
key: #args.parse().unwrap(), | ||
value: attr.#field_name.as_str().parse().unwrap(), | ||
index: false, | ||
} |
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 is the old way to do it. Can you have the return value be as it was, e.g.
impl From<PortIdAttribute> for abci::EventAttribute {
fn from(attr: PortIdAttribute) -> Self {
(PORT_ID_ATTRIBUTE_KEY, attr.port_id.as_str()).into()
}
}
May I ask what problem this is solving and what's the scope for this? Is it only used to derive the From implementation? To me it sounds a bit overkill to introduce a whole new crate and a proc macro to save on 4 lines of code per event that won't change substantially in the future. |
How we really want to save on those 4 lines, how about using a declarative macro instead? eg. event_attr!(PortIdAttribute, PORTID_ATTR_KEY, port_id); |
What I liked about the proc v/s declarative macro approach was that you didn't have to specify anything other than the attr key const, but I agree this is overkill as there are more additions in the PR than there are deletions ( |
Thank you @DaviRain-Su for this. Unfortunately we'll close it for the reasons discussed. |
Understand |
Closes: #214
Description
This is my implementation of the
abci_tag proco marco
implementation of the feeling that there is still a toy Everyone see what other improvements, this implementation is to solve the problems raised in this issue.PR author checklist:
unclog
.docs/
).Reviewer checklist:
Files changed
in the GitHub PR explorer.