[−][src]Trait sval::stream::Stream
A receiver for the structure of a value.
The Stream
trait has a flat, stateless structure, but it may need to work with
nested values. Implementations can use a Stack
to track state for them.
The OwnedStream
type is an ergonomic wrapper over a raw Stream
that adds
the concept of Value
s.
Implementing Stream
A stream may choose what kinds of structures it supports by selectively
implementing methods on the trait. Other methods default to returning
Error::unsupported
. Implementations may also choose to return
Error::unsupported
for other reasons.
Supporting primitives
The following stream can support any primitive value:
use sval::{stream, Stream}; impl Stream for MyStream { fn fmt(&mut self, args: stream::Arguments) -> stream::Result { .. Ok(()) } fn i128(&mut self, v: i128) -> stream::Result { .. Ok(()) } fn u128(&mut self, v: u128) -> stream::Result { .. Ok(()) } fn f64(&mut self, v: f64) -> stream::Result { .. Ok(()) } fn bool(&mut self, v: bool) -> stream::Result { .. Ok(()) } fn str(&mut self, v: &str) -> stream::Result { .. Ok(()) } fn none(&mut self) -> stream::Result { .. Ok(()) } }
Supporting maps
In addition to the methods needed for streaming primitives, a stream that supports maps needs to implement a few additional methods:
use sval::{stream, Stream}; impl Stream for MyStream { fn map_begin(&mut self, len: Option<usize>) -> stream::Result { .. Ok(()) } fn map_key(&mut self) -> stream::Result { .. Ok(()) } fn map_value(&mut self) -> stream::Result { .. Ok(()) } fn map_end(&mut self) -> stream::Result { .. Ok(()) } }
Supporting sequences
In addition to the methods needed for streaming primitives, a stream that supports sequences needs to implement a few additional methods:
use sval::{stream, Stream}; impl Stream for MyStream { fn seq_begin(&mut self, len: Option<usize>) -> stream::Result { .. Ok(()) } fn seq_elem(&mut self) -> stream::Result { .. Ok(()) } fn seq_end(&mut self) -> stream::Result { .. Ok(()) } }
Supporting all structure
use sval::{stream, Stream}; impl Stream for MyStream { fn fmt(&mut self, args: stream::Arguments) -> stream::Result { .. Ok(()) } fn i128(&mut self, v: i128) -> stream::Result { .. Ok(()) } fn u128(&mut self, v: u128) -> stream::Result { .. Ok(()) } fn f64(&mut self, v: f64) -> stream::Result { .. Ok(()) } fn bool(&mut self, v: bool) -> stream::Result { .. Ok(()) } fn str(&mut self, v: &str) -> stream::Result { .. Ok(()) } fn none(&mut self) -> stream::Result { .. Ok(()) } fn map_begin(&mut self, len: Option<usize>) -> stream::Result { .. Ok(()) } fn map_key(&mut self) -> stream::Result { .. Ok(()) } fn map_value(&mut self) -> stream::Result { .. Ok(()) } fn map_end(&mut self) -> stream::Result { .. Ok(()) } fn seq_begin(&mut self, len: Option<usize>) -> stream::Result { .. Ok(()) } fn seq_elem(&mut self) -> stream::Result { .. Ok(()) } fn seq_end(&mut self) -> stream::Result { .. Ok(()) } }
Provided methods
fn fmt(&mut self, args: Arguments) -> Result
Stream a format.
fn i64(&mut self, v: i64) -> Result
Stream a signed integer.
fn u64(&mut self, v: u64) -> Result
Stream an unsigned integer.
fn i128(&mut self, v: i128) -> Result
Stream a 128bit signed integer.
fn u128(&mut self, v: u128) -> Result
Stream a 128bit unsigned integer.
fn f64(&mut self, v: f64) -> Result
Stream a floating point value.
fn bool(&mut self, v: bool) -> Result
Stream a boolean.
fn char(&mut self, v: char) -> Result
Stream a unicode character.
fn str(&mut self, v: &str) -> Result
Stream a UTF-8 string slice.
fn none(&mut self) -> Result
Stream an empty value.
fn map_begin(&mut self, len: Option<usize>) -> Result
Begin a map.
fn map_key(&mut self) -> Result
Begin a map key.
The key will be implicitly ended by the stream methods that follow it.
fn map_value(&mut self) -> Result
Begin a map value.
The value will be implicitly ended by the stream methods that follow it.
fn map_end(&mut self) -> Result
End a map.
fn seq_begin(&mut self, len: Option<usize>) -> Result
Begin a sequence.
fn seq_elem(&mut self) -> Result
Begin a sequence element.
The element will be implicitly ended by the stream methods that follow it.
fn seq_end(&mut self) -> Result
End a sequence.
Implementations on Foreign Types
impl<'a, T: ?Sized> Stream for &'a mut T where
T: Stream,
[src]
T: Stream,