Skip to main content

HopperBehavior

Trait HopperBehavior 

Source
pub trait HopperBehavior<T: LayoutContract> {
    type Args;
    type CheckOutput;

    const RUN_CHECK: bool = true;
    const RUN_UPDATE: bool = false;
    const RUN_EXIT: bool = false;
    const REQUIRES_MUT: bool = _;
    const WRITES: &'static [BehaviorWrite] = _;

    // Provided methods
    fn check(
        view: &AccountView<'_>,
        state: &T,
        args: &Self::Args,
    ) -> Result<Self::CheckOutput, ProgramError> { ... }
    fn update(
        view: &AccountView<'_>,
        state: &mut T,
        args: &Self::Args,
    ) -> ProgramResult { ... }
    fn exit(view: &AccountView<'_>, args: &Self::Args) -> ProgramResult { ... }
}
Expand description

A packageable per-field lifecycle plugin over layout type T.

Implement on a unit struct; attach per-field with parameterized args. All phase methods default to no-ops so a behavior overrides only what it needs. See the module docs for the phase table and proof-token and write-range contracts.

Provided Associated Constants§

Source

const RUN_CHECK: bool = true

Whether check runs after load. The default is enabled; a behavior that validates nothing should say so explicitly).

Source

const RUN_UPDATE: bool = false

Whether update runs after validation. Requires a mut field.

Source

const RUN_EXIT: bool = false

Whether exit runs in the epilogue. Requires a mut field.

Source

const REQUIRES_MUT: bool = _

Whether the attached field must be mutable.

Source

const WRITES: &'static [BehaviorWrite] = _

Field-relative byte ranges update/exit may write. Callers or code generation can incorporate these ranges into a context WritePolicy. An empty slice declares no behavior-owned write ranges.

Required Associated Types§

Source

type Args

Per-use parameters, such as a max_bps value. Callers construct this value and pass it to the phase helpers.

Source

type CheckOutput

Behavior-defined proof payload returned by a successful check (use () when the token alone is enough). Carried inside BehaviorChecked<B>.

Provided Methods§

Source

fn check( view: &AccountView<'_>, state: &T, args: &Self::Args, ) -> Result<Self::CheckOutput, ProgramError>

Validate the loaded state; return the proof payload.

Source

fn update( view: &AccountView<'_>, state: &mut T, args: &Self::Args, ) -> ProgramResult

Mutate state after validation (only with RUN_UPDATE).

Source

fn exit(view: &AccountView<'_>, args: &Self::Args) -> ProgramResult

Epilogue hook (only with RUN_EXIT).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§