Skip to main content

Crate hopper_derive

Crate hopper_derive 

Source
Expand description

Optional proc macro DX layer for Hopper.

Provides both the canonical #[hopper::state], #[hopper::context], #[hopper::program] surface and the legacy #[hopper_state], #[hopper_context], #[hopper_program] aliases. All entry points generate zero-cost code targeting Hopper’s runtime primitives.

Not required. Every feature these macros provide is achievable through Hopper’s declarative macro_rules! macros or hand-written code. These exist purely for developer velocity. The generated code compiles to the exact same pointer arithmetic as raw Pinocchio.

§Design Philosophy

  • Macros generate code, not behavior. No hidden runtime logic.
  • Everything inlines. No function calls that wouldn’t exist in hand-written code.
  • No heap. Generated code is no_std, no_alloc.
  • Optional. Core Hopper never depends on this crate.

Macros§

declare_program
Generate a typed CPI surface from an on-disk Hopper manifest.

Attribute Macros§

account
Anchor / Quasar naming alias for [state].
accounts
Anchor-style plural alias for [context].
args
Short alias: #[hopper::args].
constant
Short alias: #[hopper::constant].
context
crank
Short alias: #[hopper::crank].
dynamic
Short alias: #[hopper::dynamic(field = "…")].
dynamic_account
Short alias: #[hopper::dynamic_account].
error
Short alias: #[hopper::error].
event
Short alias: #[hopper::event].
hopper_args
Derive a zero-copy borrowing parser for an instruction argument struct.
hopper_constant
Mark a pub const so it is surfaced in the Anchor IDL "constants" array.
hopper_context
Generate typed context accessors with segment-level borrow tracking.
hopper_crank
Mark an instruction handler as an autonomous crank.
hopper_dynamic
Declare which field of a #[repr(C)] struct is the dynamic-tail region.
hopper_dynamic_account
Quasar-style bounded dynamic fields lowered into Hopper’s fixed-body + compact-tail account layout.
hopper_error
Derive a Hopper error-code enum. Emits code(), variant_name(), From<T> for u32, and two const tables (CODE_TABLE, INVARIANT_TABLE) that the schema crate surfaces in the manifest.
hopper_event
Derive a Hopper event: emits a stable 1-byte tag, optional segment source, a NAME string, a FIELD_COUNT const, and an as_bytes(&self) view for the framework’s log-emission pathway.
hopper_migrate
Declare a schema-epoch migration edge.
hopper_pod
Derive the Hopper zero-copy marker contract for a user-defined struct.
hopper_program
Generate a dispatch table for a Hopper program module.
hopper_state
Generate a SegmentMap implementation for a zero-copy layout struct.
migrate
Short alias: #[hopper::migrate]. Functionally identical to #[hopper_migrate].
pod
Short alias: #[hopper::pod]. Functionally identical to #[hopper_pod].
program
state

Derive Macros§

Accounts
#[derive(Accounts)] - Anchor-spelled drop-in for #[hopper::context].
HopperInitSpace
Derive const INIT_SPACE: usize = size_of::<Self>() on a struct.