feat(dan): template macro handles component state #4380
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
self
) are transparently handled to the user code:u32
type component idself
parameter&mut self
) then we call the engine to update the component state()
) are now supported in functions (see theState.set
function as an example)ast.rs
module with convenient functions to detectself
and constructor functionsMotivation and Context
Following the previous work on the template macro (#4358, #4361), this PR aims to solve some of the previous limitations:
self
must be handledWith those implemented, the
state
test example is now written as:Please keep in mind that this is the simplest example that manages the contract state, but it currently supports function logic as complex as the user wants, as long as it is valid Rust code.
Also, for now I didn't find necessary to mark constructor functions in any special way. Right now, a function is automatically considered a constructor (and the component instantiated) if it returns
Self
.Lastly, as the state managing itself is not yet implemented on the engine, state is not conserved between calls. But this PR encapsulates component related logic in a single module (
component.rs
) so it should be relatively simple to implement in the future.How Has This Been Tested?
The unit test for the
state
example, now rewritten using the template macro, pass