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
impl StateStack
Sourcepub fn current(&self) -> Option<&Frame>
pub fn current(&self) -> Option<&Frame>
Return the current top frame, or None if the root value has been consumed.
Sourcepub fn expect_key_allowed(&self) -> Result<()>
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.
Sourcepub fn expect_value_allowed(&self) -> Result<()>
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.
Sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Returns true when all containers have been closed and the root value consumed.
Sourcepub fn mark_key_written(&mut self) -> Result<()>
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).
Sourcepub fn mark_value_written(&mut self) -> Result<()>
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).
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new StateStack containing a single Frame::Root.
Sourcepub fn peek_array(&self) -> Result<()>
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.
Sourcepub fn peek_object(&self) -> Result<()>
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).
Sourcepub fn pop(&mut self) -> Result<Frame>
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.
Sourcepub fn pop_array(&mut self) -> Result<()>
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.
Sourcepub fn pop_object(&mut self) -> Result<()>
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.
Sourcepub fn push_array(&mut self)
pub fn push_array(&mut self)
Push a new Array frame.
Sourcepub fn push_object(&mut self)
pub fn push_object(&mut self)
Push a new Object frame in ExpectingKey state.