Skip to main content

HopperProgramPolicy

Struct HopperProgramPolicy 

Source
pub struct HopperProgramPolicy {
    pub strict: bool,
    pub enforce_token_checks: bool,
    pub allow_unsafe: bool,
}
Expand description

Program-level safety policy emitted by #[hopper::program(...)].

Each field is a compile-time lever. The const value ends up inlined at every call site the program evaluates it from, so the branches fold away when a lever is known to be on or off at compile time.

Fields§

§strict: bool

Program-level intent marker: handlers in this program run under Hopper’s full enforcement envelope.

The actual per-handler behaviour is controlled by the handler’s context parameter type. A handler typed as Context<MyAccounts> always runs MyAccounts::bind(ctx)? (which chains into validate(ctx)?) regardless of policy. A handler typed as &mut Context<'_> always receives the context raw. strict = true is the documentation contract that every handler in the module opts into the typed form; strict = false signals the author intends to use raw contexts and accepts the responsibility of calling validate() manually where needed.

The flag is read back by callers at compile time (HOPPER_PROGRAM_POLICY.strict) to specialize code paths that depend on whether the enforcement envelope is active.

§enforce_token_checks: bool

Token CPI authors must pair every raw invocation with the matching *Checked builder (which carries the decimals: u8 byte the SPL Token program validates against the mint). Handlers that do their own SPL plumbing read this back to decide whether the signer + owner invariants are already upheld elsewhere.

§allow_unsafe: bool

Permit unsafe { ... } blocks inside handler bodies. When false the program macro wraps each handler in #[deny(unsafe_code)] so the compiler rejects any raw pointer detour.

Implementations§

Source§

impl HopperProgramPolicy

Source

pub const STRICT: Self

Every safety lever engaged. The shipping default.

Source

pub const SEALED: Self

Strict + token checks + no unsafe in handlers. The zero-escape mode for programs that never want to drop to raw pointers.

Source

pub const RAW: Self

Every lever disengaged. Pinocchio-parity throughput with responsibility pushed to the handler author.

Source

pub const fn default_policy() -> Self

The shipping default, identical to HopperProgramPolicy::STRICT.

Exposed as a const fn so downstream macro expansion can reach it from const context without an intermediate binding.

Trait Implementations§

Source§

impl Clone for HopperProgramPolicy

Source§

fn clone(&self) -> HopperProgramPolicy

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HopperProgramPolicy

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for HopperProgramPolicy

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for HopperProgramPolicy

Source§

fn eq(&self, other: &HopperProgramPolicy) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for HopperProgramPolicy

Source§

impl Eq for HopperProgramPolicy

Source§

impl StructuralPartialEq for HopperProgramPolicy

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.