[−][src]Struct sval::stream::stack::Stack
A container for the stream state.
Implementations of the Stream
trait are encouraged to use a
stack for validating their input.
The stack is stateful, and keeps track of open maps and sequences.
Validation
A stack uses its state to validate the structure given to a stream and as a way for a flat, stateless stream to know what it's currently looking at. The stack enforces:
- Only a single root primitive, map or sequence is received.
- Map keys and values are only received within a map.
- Map keys are always received before map values, and every key has a corresponding value.
- Sequence elements are only received within a sequence.
- Every map and sequence is ended, and in the right order.
- Every map key, map value, and sequence element is followed by valid data.
Depth
By default, stacks have a fixed depth (currently ~16, but this may change) so they can
work in no-std environments. Each call to map_begin
or seq_begin
will increase the
current depth. If this depth is exceeded then calls to map_begin
or seq_begin
will fail.
The fixed-depth limit can be removed by adding the arbitrary-depth
feature to your Cargo.toml
(this also requires the standard library):
[dependencies.sval]
features = ["arbitrary-depth"]
Methods
impl Stack
[src]
pub fn new() -> Self
[src]
Create a new stack.
pub fn clear(&mut self)
[src]
Clear the stack so that it can be re-used.
Any state it currently contains will be lost.
pub fn current(&self) -> Pos
[src]
Get the current position in the stack.
pub fn primitive(&mut self) -> Result<Pos, Error>
[src]
Push a primitive.
A primitive is a simple value that isn't a map or sequence. That includes:
Arguments
u64
,i64
,u128
,i128
f64
bool
char
,&str
Option<T>
.
pub fn map_begin(&mut self) -> Result<Pos, Error>
[src]
Begin a new map.
The map must be completed by calling map_end
.
pub fn map_key(&mut self) -> Result<Pos, Error>
[src]
Begin a map key.
The key will be implicitly completed by the value that follows it.
pub fn map_value(&mut self) -> Result<Pos, Error>
[src]
Begin a map value.
The value will be implicitly completed by the value that follows it.
pub fn map_end(&mut self) -> Result<Pos, Error>
[src]
Complete the current map.
pub fn seq_begin(&mut self) -> Result<Pos, Error>
[src]
Begin a new sequence.
the sequence must be completed by calling seq_end
.
pub fn seq_elem(&mut self) -> Result<Pos, Error>
[src]
Begin a sequence element.
The element will be implicitly completed by the value that follows it.
pub fn seq_end(&mut self) -> Result<Pos, Error>
[src]
Complete the current sequence.
pub fn can_end(&self) -> bool
[src]
Whether or not the stack has seen a complete and valid stream.
pub fn end(&mut self) -> Result<(), Error>
[src]
Complete the stack.
This stack may be re-used after being completed
by calling begin
.
Trait Implementations
impl Clone for Stack
[src]
fn clone(&self) -> Stack
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Default for Stack
[src]
Auto Trait Implementations
impl Unpin for Stack
impl Send for Stack
impl Sync for Stack
impl RefUnwindSafe for Stack
impl UnwindSafe for Stack
Blanket Implementations
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,