-
Notifications
You must be signed in to change notification settings - Fork 67
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 a macro attribute for auto-unwrapping vals #9
Conversation
edition = "2021" | ||
|
||
[lib] | ||
proc-macro = true |
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.
Seems to cause rust-lang/rust#93988 on macos, but probably an insignificant issue.
Ah, I wish I'd caught this earlier. Apologies for slow uptake. In general I've a fairly strong desire not to provide any macros in the SDK, especially procedural ones. Almost all the Rust SDKs for other smart contract system are "big piles of macros" and I think it's a very problematic approach:
In this case in particular, users are taken a step away from the dynamic
|
I should also point out that the example is a bit exaggerated. It would read:
|
While experimenting in both rust and assemblyscript, writing wrapping encoders/decoders was annoying, and made it harder to read the contract code at hand. This was something @paulbellamy noticed as well. I don't think we should use macros everywhere, but if we use a macro to wrap the function, and then have the SDK otherwise expose only non-Val types, the developer will not need to interact with Vals. |
The alternative is we just encourage devs to write these functions manually, which is not horrible, as you pointed out because of the as_ functions. Maybe we should add .into functions? |
Closing in favor of writing these out by hand without a macro. |
+1 on macros being bad. -1 on devs interacting with |
What
Add a macro attribute for auto-unwrapping and rewrapping vals.
Why
So that we can write contracts that look like this:
That end up being converted into:
cc @graydon
cc @paulbellamy