Expand description
Derive macros for InstructionDecoder implementations
This crate provides two macros:
#[derive(InstructionDecoder)]- For instruction enums (native programs)#[instruction_decoder]- Attribute macro for Anchor program modules
The attribute macro extracts function names from the program module and generates
an instruction enum with #[derive(InstructionDecoder)] applied.
§Enhanced InstructionDecoder for Anchor Programs
The derive macro supports an enhanced mode that references Anchor-generated types for account names and parameter decoding:
ⓘ
use light_instruction_decoder_derive::InstructionDecoder;
#[derive(InstructionDecoder)]
#[instruction_decoder(
program_id = "MyProgram111111111111111111111111111111111",
program_name = "My Program"
)]
pub enum MyInstruction {
#[instruction_decoder(accounts = CreateRecord, params = CreateRecordParams)]
CreateRecord,
#[instruction_decoder(accounts = UpdateRecord)]
UpdateRecord,
}This generates a decoder that:
- Gets account names from
<AccountsType<'_>>::ACCOUNT_NAMES - Decodes instruction data using
ParamsType::try_from_slice()with Debug output
Attribute Macros§
- instruction_
decoder - Attribute macro for generating InstructionDecoder from Anchor program modules.
Derive Macros§
- Instruction
Decoder - Derives an InstructionDecoder implementation for an Anchor instruction enum.