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§
Sourceconst RUN_CHECK: bool = true
const RUN_CHECK: bool = true
Whether check runs after load. The default is enabled; a behavior that
validates nothing should say so explicitly).
Sourceconst RUN_UPDATE: bool = false
const RUN_UPDATE: bool = false
Whether update runs after validation. Requires a mut field.
Sourceconst REQUIRES_MUT: bool = _
const REQUIRES_MUT: bool = _
Whether the attached field must be mutable.
Sourceconst WRITES: &'static [BehaviorWrite] = _
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§
Sourcetype Args
type Args
Per-use parameters, such as a max_bps value. Callers construct this
value and pass it to the phase helpers.
Sourcetype CheckOutput
type CheckOutput
Behavior-defined proof payload returned by a successful check
(use () when the token alone is enough). Carried inside
BehaviorChecked<B>.
Provided Methods§
Sourcefn check(
view: &AccountView<'_>,
state: &T,
args: &Self::Args,
) -> Result<Self::CheckOutput, ProgramError>
fn check( view: &AccountView<'_>, state: &T, args: &Self::Args, ) -> Result<Self::CheckOutput, ProgramError>
Validate the loaded state; return the proof payload.
Sourcefn update(
view: &AccountView<'_>,
state: &mut T,
args: &Self::Args,
) -> ProgramResult
fn update( view: &AccountView<'_>, state: &mut T, args: &Self::Args, ) -> ProgramResult
Mutate state after validation (only with RUN_UPDATE).
Sourcefn exit(view: &AccountView<'_>, args: &Self::Args) -> ProgramResult
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".