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 Ctx<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

Author-maintained token-check intent. The macro records this flag without inserting or removing checks from CPI calls. Explicit strict methods on TransferChecked, BurnChecked, and ApproveChecked check the token owner field; their direct variants also require signer privilege. Signed strict variants accept PDA seeds, whose signing authority is validated during CPI rather than requiring an incoming signer flag.

§allow_unsafe: bool

Permit unsafe { ... } blocks inside handler bodies. When false the program macro wraps each handler in #[deny(unsafe_code)]. The lint covers that handler item, not called helpers or dependencies, and ordinary Rust lint override rules apply.

Implementations§

Source§

impl HopperProgramPolicy

Source

pub const STRICT: Self

Typed-validation and token-check intent enabled; unsafe code permitted. The shipping default. Handler types and helper calls determine checks.

Source

pub const SEALED: Self

STRICT intent plus a default unsafe-code denial on handler items. This does not audit unsafe implementations in called helpers.

Source

pub const RAW: Self

Typed-validation and token-check intent disabled; unsafe code permitted. Typed handlers still bind. Raw handlers own their explicit validation.

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) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for HopperProgramPolicy

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 Eq for HopperProgramPolicy

Source§

impl PartialEq for HopperProgramPolicy

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.