Skip to main content

StateSnapshot

Struct StateSnapshot 

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

A stack-allocated snapshot of account data.

SIZE is the maximum number of bytes captured.

Implementations§

Source§

impl<const SIZE: usize> StateSnapshot<SIZE>

Source

pub fn capture(data: &[u8]) -> Self

Capture a snapshot of account data.

If the data is longer than SIZE, only the first SIZE bytes are captured and was_truncated() returns true.

Source

pub fn len(&self) -> usize

Length of captured data.

Source

pub fn is_empty(&self) -> bool

Whether no data was captured.

Source

pub fn was_truncated(&self) -> bool

Whether the source data was larger than the snapshot buffer.

Source

pub fn data(&self) -> &[u8]

Get the captured data.

Source

pub fn diff<'a>(&'a self, current: &'a [u8]) -> StateDiff<'a>

Compute a diff against current data.

Returns a StateDiff describing all changed regions.

Source

pub fn has_changes(&self, current: &[u8]) -> bool

Check if any bytes changed compared to current data.

Source

pub fn range_changed(&self, current: &[u8], offset: usize, len: usize) -> bool

Check if a specific byte range changed.

Source

pub fn restore_into(&self, target: &mut [u8]) -> Result<(), ProgramError>

Restore the snapshot data back into a mutable slice.

Useful for rollback scenarios.

Auto Trait Implementations§

§

impl<const SIZE: usize> Freeze for StateSnapshot<SIZE>

§

impl<const SIZE: usize> RefUnwindSafe for StateSnapshot<SIZE>

§

impl<const SIZE: usize> Send for StateSnapshot<SIZE>

§

impl<const SIZE: usize> Sync for StateSnapshot<SIZE>

§

impl<const SIZE: usize> Unpin for StateSnapshot<SIZE>

§

impl<const SIZE: usize> UnsafeUnpin for StateSnapshot<SIZE>

§

impl<const SIZE: usize> UnwindSafe for StateSnapshot<SIZE>

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.