-
Notifications
You must be signed in to change notification settings - Fork 337
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
Add IntoEvent macro which automatically implement Into<Event> to a struct #2038
Conversation
move IntoEvent macro to cosmwasm-derive feat: add attribute "use_to_string" to IntoEvent derive macro
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.
Thanks for bringing this up!
I think this is a good approach, but the derive macro is a bit out of scope for cosmwasm-std.
I suggest we merge the Into<Event>
change and then the derive macro can be a separate crate that you could even maintain yourself.
Also note that attributes can be added both to events and responses directly, so maybe a more general solution for generating attributes makes more sense? This was brought up in #1928 before.
#[test] | ||
fn using_into_event() { | ||
// IntoEvent can be used only when cosmwasm_std is imported as `cosmwasm_std` | ||
use crate as cosmwasm_std; |
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.
Neat!
It looks good! Should I reopen a new PR for it? Or will you do it? |
@loloicci Yes, either a new PR or rebase this one. Also, please add a changelog entry for it under the "Unreleased" section. |
@chipshort |
This PR suggests and implements a derive macro for structs named
IntoEvent
which is for developers of contracts.With this,
#[derive(IntoEvent)]
implementsInto<Event>
to a decorated struct.This makes it easier to make a structure representing an event.
An Example usage:
See the document of
derive_into_event
in packages/derive/src/lib.rs to learn how to use it.See tests in packages/std/src/results/response.rs for more example usages.