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>
impl<const N: usize> ReallocGuard<N>
Sourcepub fn register(&mut self, slot: usize, size: usize) -> Result<(), ProgramError>
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.
Sourcepub fn check_growth(
&self,
slot: usize,
new_size: usize,
) -> Result<(), ProgramError>
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.
Sourcepub fn commit_growth(
&mut self,
slot: usize,
new_size: usize,
) -> Result<(), ProgramError>
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.
Sourcepub fn slot_growth(&self, slot: usize) -> i32
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more