Skip to main content

StateStack

Struct StateStack 

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

Stack tracking the current JSON emission context.

Each push corresponds to opening an object or array; each pop corresponds to closing one. The root frame represents the outermost document level.

Implementations§

Source§

impl StateStack

Source

pub fn current(&self) -> Option<&Frame>

Return the current top frame, or None if the root value has been consumed.

Source

pub fn expect_key_allowed(&self) -> Result<()>

Validate that a key is allowed. OK only when current frame is Object(ExpectingKey).

§Errors

Returns Err if a key is not allowed at the current position.

Source

pub fn expect_value_allowed(&self) -> Result<()>

Validate that a value is allowed. OK when: Object(ExpectingValue), Array, or Root.

§Errors

Returns Err if a value is not allowed at the current position.

Source

pub fn is_finished(&self) -> bool

Returns true when all containers have been closed and the root value consumed.

Source

pub fn mark_key_written(&mut self) -> Result<()>

Mark a key as written — transition Object from ExpectingKey to ExpectingValue.

§Errors

Returns Err if the current frame is not Object(ExpectingKey).

Source

pub fn mark_value_written(&mut self) -> Result<()>

Mark a value as written.

Transitions: Object(ExpectingValue)ExpectingKey; Root → pop; Array → no-op.

§Errors

Returns Err if called in Object(ExpectingKey) state (value without key).

Source

pub fn new() -> Self

Create a new StateStack containing a single Frame::Root.

Source

pub fn peek_array(&self) -> Result<()>

Validate that the top frame is an Array without popping.

§Errors

Returns Err if the current frame is not an Array.

Source

pub fn peek_object(&self) -> Result<()>

Validate that the top frame is an Object in ExpectingKey state, without popping.

§Errors

Returns Err if the current frame is not an Object, or if the Object is in ExpectingValue state (a key was written but its value hasn’t been emitted).

Source

pub fn pop(&mut self) -> Result<Frame>

Pop the top frame. Returns Err if the stack is empty.

§Errors

Returns Err if there is no open container to close.

Source

pub fn pop_array(&mut self) -> Result<()>

Pop the top frame, asserting it is an Array. Returns Err if it is not.

§Errors

Returns Err if the current frame is not an Array.

Source

pub fn pop_object(&mut self) -> Result<()>

Pop the top frame, asserting it is an Object expecting a key. Returns Err if it is not.

§Errors

Returns Err if the current frame is not an Object expecting a key.

Source

pub fn push_array(&mut self)

Push a new Array frame.

Source

pub fn push_object(&mut self)

Push a new Object frame in ExpectingKey state.

Trait Implementations§

Source§

impl Default for StateStack

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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.