solzempic-macros 0.1.0

Proc macros for Solzempic Solana framework
Documentation
  • Coverage
  • 80%
    4 out of 5 items documented0 out of 4 items with examples
  • Size
  • Source code size: 34.69 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 402.27 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 4s Average build duration of successful builds.
  • all releases: 4s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • mgild/solzempic
    10 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • mgild

Procedural macros for the Solzempic framework.

This crate provides compile-time code generation for Solana programs built with Solzempic. The macros reduce boilerplate while maintaining zero runtime overhead through compile-time expansion.

Available Macros

Macro Type Purpose
[SolzempicDispatch] Attribute Dispatch enum + framework types
[instruction] Attribute Instruction trait implementations
[Account] Derive Account struct with discriminator

Quick Start

use solzempic::SolzempicDispatch;

// 1. Define dispatch enum (generates framework types)
#[SolzempicDispatch("Your11111111111111111111111111111111111111")]
pub enum MyInstruction {
    Initialize = 0,
    Transfer = 1,
}

// 2. Define instruction struct
pub struct Transfer<'a> {
    from: AccountRefMut<'a, TokenAccount>,
    to: AccountRefMut<'a, TokenAccount>,
}

// 3. Implement with #[instruction] macro
#[instruction(TransferParams)]
impl<'a> Transfer<'a> {
    fn build(accounts: &'a [AccountInfo], params: &TransferParams) -> Result<Self, ProgramError> {
        // Parse accounts...
    }

    fn validate(&self, program_id: &Pubkey, params: &TransferParams) -> ProgramResult {
        // Validate state...
    }

    fn execute(&self, program_id: &Pubkey, params: &TransferParams) -> ProgramResult {
        // Execute logic...
    }
}

// 4. In entrypoint:
MyInstruction::process(program_id, accounts, instruction_data)?;

Generated Code

From SolzempicDispatch

  • ID - Program ID constant
  • Solzempic - Framework type implementing Framework trait
  • AccountRef<'a, T> - Type alias for read-only accounts
  • AccountRefMut<'a, T> - Type alias for writable accounts
  • ShardRefContext<'a, T> - Type alias for shard triplets
  • id() - Returns &'static Pubkey
  • TryFrom<u8> - Discriminator parsing
  • dispatch() - Handler dispatch (after enum construction)
  • process() - Direct dispatch (more efficient)

From instruction

  • InstructionParams impl with associated Params type
  • Instruction<'a> impl with build, validate, execute methods

From Account derive

  • #[repr(C)] for stable memory layout
  • Clone, Copy, Pod, Zeroable derives
  • Prepended discriminator: [u8; 8] field
  • Loadable impl for zero-copy loading

Performance

All macros expand at compile time with zero runtime cost. The process() method is more efficient than dispatch() because it avoids constructing the enum variant before dispatching.