instruction_decoder_collection!() { /* proc-macro */ }
Expand description
Generates a collection of instruction decoders and associated enums.
This macro creates a set of enums and implementations to handle decoding of instructions for multiple Solana programs. It generates:
- An enum for all instructions
- An enum for all instruction types
- An enum for all programs
- An implementation of InstructionDecoderCollection trait
§Syntax
The macro takes the following arguments:
- Name for the all-encompassing instructions enum
- Name for the all-encompassing instruction types enum
- Name for the programs enum
- One or more entries, each consisting of:
- Program variant name
- Decoder expression
- Instruction enum for the program
§Example
ⓘ
instruction_decoder_collection!(
AllInstructions, AllInstructionTypes, AllPrograms,
JupSwap => JupiterDecoder => JupiterInstruction,
MeteoraSwap => MeteoraDecoder => MeteoraInstruction
);
This example will generate:
- AllInstructions enum with variants JupSwap(JupiterInstruction) and MeteoraSwap(MeteoraInstruction)
- AllInstructionTypes enum with variants JupSwap(JupiterInstructionType) and MeteoraSwap(MeteoraInstructionType)
- AllPrograms enum with variants JupSwap and MeteoraSwap
- An implementation of InstructionDecoderCollection for AllInstructions
§Generated Code
The macro generates the following:
- An enum AllInstructions containing variants for each program’s instructions
- An enum AllInstructionTypes containing variants for each program’s instruction types
- An enum AllPrograms listing all programs
- An implementation of InstructionDecoderCollection for AllInstructions,
including:
- parse_instruction method to decode instructions
- get_type method to retrieve the instruction type
§Note
Ensure that all necessary types (e.g., DecodedInstruction, InstructionDecoderCollection) are in scope where this macro is used.