Skip to main content

ReallocGuard

Struct ReallocGuard 

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

Per-instruction realloc budget guard.

N is the maximum number of accounts to track (const generic, stack-allocated). Typical values: 4, 8, or 16.

Implementations§

Source§

impl<const N: usize> ReallocGuard<N>

Source

pub const fn new(budget: u32) -> Self

Create a new guard with the given growth budget (bytes).

Source

pub fn register(&mut self, slot: usize, size: usize) -> Result<(), ProgramError>

Register an account’s original size for tracking.

slot is the local tracking index (0..N-1), not the account index. size is the current data length. Returns Err if slot >= N.

Source

pub fn check_growth( &self, slot: usize, new_size: usize, ) -> Result<(), ProgramError>

Check if growing account slot to new_size is within budget.

Does NOT commit the growth – call commit_growth after the actual realloc succeeds.

Source

pub fn commit_growth( &mut self, slot: usize, new_size: usize, ) -> Result<(), ProgramError>

Commit a growth after successful realloc.

Must be called after the actual safe_realloc succeeds. Returns Err if slot is not registered.

Source

pub const fn remaining(&self) -> u32

Remaining budget (bytes).

Source

pub const fn consumed(&self) -> u32

Total consumed growth (bytes).

Source

pub const fn budget(&self) -> u32

Budget cap (bytes).

Source

pub fn slot_growth(&self, slot: usize) -> i32

Growth of a specific slot from its original size (bytes).

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

§

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