ScopeSnapshot

Struct ScopeSnapshot 

Source
pub struct ScopeSnapshot { /* private fields */ }
Expand description

A snapshot of the staging-related fields of EvalCtx. Used to save and restore the staging context at scope boundaries (reify, reifyc, reifyv, run_now, Catch).

Replaces the closure-passed run_scope pattern of the recursive baseline with a value we can name, hold on a continuation, and inspect in tests. The discipline is identical: every save must be paired with exactly one restore.

level is not part of ScopeSnapshot because it’s saved independently in RunNowExitlevel only changes at run-now boundaries, not at every reify scope.

Implementations§

Source§

impl ScopeSnapshot

Source

pub fn save(ctx: &mut EvalCtx) -> Self

Save the current staging state. The saved block is taken via mem::take — callers who want to start fresh in the new scope will set ctx.block = Vec::new() afterwards (typically via save_and_reset_block for ergonomics).

fun is Rc::cloned (O(1) refcount bump, not a structural copy).

Source

pub fn save_and_reset_block(ctx: &mut EvalCtx) -> Self

Save and reset block to empty. Equivalent to:

let snap = ScopeSnapshot::save(ctx);
// ctx.block is already Vec::new() because mem::take left it empty.

Provided for symmetry with save — most reify-style scopes want the block reset, so this is the common path. Functionally equivalent to plain save but more explicit at the call site.

Source

pub fn restore(self, ctx: &mut EvalCtx)

Restore the saved state into ctx. Consumes the snapshot — each snapshot may be restored at most once.

Auto Trait Implementations§

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.