lang: Add #[instruction]
attribute proc-macro
#3137
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.
Problem
There is no way to override the default 8-byte Anchor discriminators of program instructions.
Summary of changes
Add
#[instruction]
attribute proc-macro that can be used to override Anchor defaults of program instructions.This macro currently only allows overriding discriminators, but the functionality can be extended to override other defaults in the future.
Example
More examples can be found in the
custom-discriminator
tests.Note
The initial design was to introduce a new
#[discriminator]
macro to share the implementation of instructions, accounts and events, as mentioned in #2728 (comment). However, given there is a demand from the users to override the other defaults of Anchor (e.g. serialization), it became clear that introducing a new macro for all of the overrides would not scale well.Note: This PR is part of a greater effort explained in #3097.