Skip to main content

ValidationGroup

Struct ValidationGroup 

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

A named group of validation rules.

Groups bundle related rules under a label for reuse across instructions. Example: a “token_transfer_preconditions” group that checks signer, writable, owner, and balance across the relevant accounts.

let mut group = ValidationGroup::<4>::new("transfer_preconditions");
group.add(require_signer_at(0))?;
group.add(require_writable_at(1))?;
group.add(require_owned_at(1))?;
group.run(&ctx)?;

Implementations§

Source§

impl<const N: usize> ValidationGroup<N>

Source

pub const fn new(name: &'static str) -> Self

Create a new named validation group.

Source

pub const fn name(&self) -> &'static str

Group name (for diagnostics/logging).

Source

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

Add a rule to the group.

Source

pub fn len(&self) -> usize

Number of rules in the group.

Source

pub fn is_empty(&self) -> bool

Whether the group has no rules.

Source

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

Run all rules in the group. Fail-fast.

Trait Implementations§

Source§

impl<const M: usize> Validatable for ValidationGroup<M>

Source§

fn validate(&self, ctx: &ValidationContext<'_>) -> ProgramResult

Run validation against the given context.

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

§

impl<const N: usize> UnwindSafe for ValidationGroup<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.