Skip to main content

StateStack

Struct StateStack 

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

A Vec-based save/restore stack of GraphicsState values.

Replaces the raw-pointer linked list (SplashState *next) in the C++ original.

§Stack invariant

The stack always contains at least one entry — the initial state passed to StateStack::new. This invariant is established by the constructor and maintained by every method:

  • save only pushes (depth grows).
  • restore refuses to pop the last entry and signals this via its bool return value.

Because the invariant holds unconditionally, the .last() / .last_mut() calls in current, current_mut, and save can never return None. The .expect() calls there exist solely to surface a bug if the invariant is ever broken during development.

Implementations§

Source§

impl StateStack

Source

pub fn new(initial: GraphicsState) -> Self

Create a new stack with initial as the sole (bottom) state.

After construction, depth returns 1.

Source

pub fn current(&self) -> &GraphicsState

Borrow the current (top) state.

§Panics

Never panics in correct code — the stack invariant guarantees at least one entry at all times. The expect is a development-time tripwire.

Source

pub fn current_mut(&mut self) -> &mut GraphicsState

Mutably borrow the current state.

§Panics

Never panics in correct code — the stack invariant guarantees at least one entry at all times. The expect is a development-time tripwire.

Source

pub fn save(&mut self)

Push a clone of the current state (PDF q operator).

§Panics

Never panics in correct code — the stack invariant guarantees at least one entry at all times. The expect is a development-time tripwire.

Source

pub fn restore(&mut self) -> bool

Pop the top state (PDF Q operator).

Returns true on success.

Returns falsewithout modifying the stack — when the stack is at depth 1 (only the initial state remains). The initial state is never popped; this preserves the stack invariant (depth ≥ 1).

Callers that receive false should treat it as an unmatched Q operator and continue rendering with the current state unchanged.

Source

pub const fn depth(&self) -> usize

Current nesting depth (1 = only the initial state, no saves in progress).

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.