macro_rules! hopper_load {
( $slice:expr => [ $($binding:ident),+ $(, ..)? $(,)? ] ) => { ... };
}Expand description
Destructuring sugar for raw-dispatch handlers.
Replaces the common pattern:
let [user, vault, system_program, ..] = accounts else {
return Err(ProgramError::NotEnoughAccountKeys);
};with the tighter form:
hopper_load!(accounts => [user, vault, system_program]);The bindings are plain &AccountView references (not owned values),
matching the destructuring pattern. A trailing .. is accepted and
discards any extra accounts. The macro bails with
ProgramError::NotEnoughAccountKeys when the slice is too short,
mirroring Hopper’s existing idiom.
Use this in the raw-dispatch authoring style (no #[hopper::context]).
The proc-macro context already binds accounts by name, so this is only
useful when you are working with &[AccountView] directly - typically
inside fn process_instruction(_, accounts: &[AccountView], _) before
routing to per-variant handlers.
§Examples
fn process_deposit(
program_id: &Address,
accounts: &[AccountView],
data: &[u8],
) -> ProgramResult {
hopper_load!(accounts => [user, vault, system_program]);
user.require_signer()?;
vault.require_writable()?;
// ... rest of handler ...
Ok(())
}With a trailing rest pattern (accept more accounts, ignore them):
hopper_load!(accounts => [user, vault, ..]);The trailing .. is redundant with the default behaviour (the macro
always accepts more accounts than declared) but is supported for
stylistic parity with the native Rust slice pattern.