[−][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]
impl Stack
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 begin(&mut self) -> Result<(), Error> | [src] |
Ensure the stack is ready for a new value.
This method only needs to be called by [Stream
]s that
can be re-used.
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]
impl Clone for Stack
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]
impl Default for Stack
Auto Trait Implementations
Blanket Implementations
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)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> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error> | [src] |
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T | [src] |
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId | [src] |
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,