Open HDauven opened 1 month ago
How the static mut STATE
gets created should also be standardised and defined. Otherwise it will be unclear how certain data structures within the field of the struct would be created and with which values.
The simplest approach here, in my opinion, would be to require the Default trait to be implemented for the public struct. This way the macro can always create the state with the default() method.
(There could also be another way with the init() function)
Summary
This issue comes from the need to simplify smart contract development on Dusk by abstracting away implementation details like the
static mut STATE
andno_mangle
functions.It follows from the discussion in the issue Investigate foreign trait exposing.
Possible solution design or implementation
We can create a
#[contract]
macro that generates the necessary boilerplate code automatically. We can take and extend the functionality of the piecrust-macros I did here, and make it do the following:#[contract]
macro should be applicable to a Rust module.no_mangle
functions for all public methods withinimpl
blocks.no_mangle
functions for every trait implementation function.static mut STATE
for a public struct defined within the module.Example
The following input:
Should generate the following output:
By implementing this feature set, developers no longer need to create the
no_mangle
functions and do not have to define the state explicitly.