pub trait InstructionDecoderCollection:
Clone
+ Debug
+ Send
+ Sync
+ Eq
+ Hash
+ Serialize
+ 'static {
type InstructionType: Clone + Debug + PartialEq + Eq + Send + Sync + 'static;
// Required methods
fn parse_instruction(
instruction: &Instruction,
) -> Option<DecodedInstruction<Self>>;
fn get_type(&self) -> Self::InstructionType;
}
Expand description
A trait for defining collections of Solana instructions, enabling parsing and type-based management.
The InstructionDecoderCollection
trait provides an interface for decoding
Solana Instruction
objects into custom types that can be processed within
the carbon-core
pipeline. This trait requires implementing methods to
parse instructions and retrieve associated instruction types, allowing for
flexible handling of different instruction variants in a single collection.
§Associated Types
InstructionType
: Defines the specific type of instruction being handled, which is expected to beClone
,Debug
,PartialEq
,Eq
,Send
, andSync
. This type is used to classify decoded instructions, making them easier to process based on their category or type.
§Required Methods
§parse_instruction
This method is responsible for converting a Solana Instruction
object into
a DecodedInstruction
containing the custom type defined by the
implementor. The parsed instruction can then be processed within the
pipeline according to application-specific logic.
- Parameters:
instruction
: A reference to asolana_instruction::Instruction
, representing the raw instruction to be decoded.
- Returns: An
Option<DecodedInstruction<Self>>
containing the decoded instruction if successful, orNone
if parsing fails or the instruction is unsupported.
§get_type
Retrieves the instruction type associated with an instruction. This type can be used to classify instructions or route them to specific processing logic based on their category.
- Returns: An instance of
Self::InstructionType
, representing the specific type of instruction.
§Notes
- This trait requires implementors to be thread-safe (
Send
andSync
) and serializable (Serialize
), which is particularly useful for distributed systems where instruction collections are transmitted across network boundaries. - The
parse_instruction
method must be implemented with care, as it determines how raw instruction data is transformed into a decoded form, impacting subsequent processing within the pipeline.
Required Associated Types§
Required Methods§
fn parse_instruction( instruction: &Instruction, ) -> Option<DecodedInstruction<Self>>
fn get_type(&self) -> Self::InstructionType
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.