carbon_core/collection.rs
1//! Multi-decoder routing primitive for transaction-level instruction dispatch.
2//!
3//! # Overview
4//!
5//! `Pipeline::transaction(...)` evaluates each instruction in a transaction
6//! against a unified enum. `InstructionDecoderCollection` defines this enum,
7//! where each variant wraps the `InstructionType` of a registered decoder.
8//! `parse_instruction` selects the matching variant for a given instruction.
9//!
10//! Typical usage is a hand-written wrapper enum over all relevant decoders,
11//! with `parse_instruction` attempting each decoder sequentially.
12//!
13//! # Notes
14//!
15//! - `Eq + Hash + Serialize` are required for internal routing and persistence.
16//! - Generated decoders (e.g. Codama) usually lack these bounds, so the wrapper
17//! enum is maintained manually or via macro.
18
19use serde::Serialize;
20
21/// Enum-based instruction router used by `Pipeline::transaction(...)`.
22///
23/// Implemented as a wrapper over multiple decoders, enabling unified
24/// dispatch of heterogeneous instruction types.
25///
26/// # Associated Types
27///
28/// - [`InstructionType`](Self::InstructionType): Discriminant returned by
29/// [`get_type`](Self::get_type), used for routing within the pipe.
30pub trait InstructionDecoderCollection:
31 Clone + std::fmt::Debug + Send + Sync + Eq + std::hash::Hash + Serialize + 'static
32{
33 type InstructionType: Clone + std::fmt::Debug + PartialEq + Eq + Send + Sync + 'static;
34
35 fn parse_instruction(instruction: &solana_instruction::Instruction) -> Option<Self>;
36
37 fn get_type(&self) -> Self::InstructionType;
38}