Skip to main content

TransitionRulePack

Struct TransitionRulePack 

Source
pub struct TransitionRulePack<const N: usize> { /* private fields */ }
Expand description

Associates validation rules with specific instruction tags.

Each instruction in your program can have its own set of checks, looked up by the dispatch tag. This avoids running irrelevant checks for instructions that don’t need them.

let mut tr = TransitionRulePack::<16>::new();
tr.add(0, validate_init_accounts)?;   // Init
tr.add(1, validate_deposit_accounts)?; // Deposit
tr.add(2, validate_withdraw_accounts)?; // Withdraw

// In handler: run only rules for this instruction
tr.run_for(instruction_tag, &ctx)?;

Implementations§

Source§

impl<const N: usize> TransitionRulePack<N>

Source

pub const fn new() -> Self

Create an empty rule pack.

Source

pub fn add( &mut self, tag: InstructionTag, rule: ValidateFn, ) -> Result<(), ProgramError>

Register a rule for a specific instruction tag.

Source

pub fn run_for( &self, tag: InstructionTag, ctx: &ValidationContext<'_>, ) -> ProgramResult

Run all rules matching the given instruction tag. Fail-fast.

Source

pub fn len(&self) -> usize

Number of entries.

Source

pub fn is_empty(&self) -> bool

Whether the rule pack has no entries.

Trait Implementations§

Source§

impl<const N: usize> Default for TransitionRulePack<N>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<const N: usize> Freeze for TransitionRulePack<N>

§

impl<const N: usize> RefUnwindSafe for TransitionRulePack<N>

§

impl<const N: usize> Send for TransitionRulePack<N>

§

impl<const N: usize> Sync for TransitionRulePack<N>

§

impl<const N: usize> Unpin for TransitionRulePack<N>

§

impl<const N: usize> UnsafeUnpin for TransitionRulePack<N>

§

impl<const N: usize> UnwindSafe for TransitionRulePack<N>

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