[][src]Trait sval::stream::Stream

pub trait Stream {
    fn fmt(&mut self, v: Arguments<'_>) -> Result { ... }
fn error(&mut self, v: Source<'_>) -> Result { ... }
fn i64(&mut self, v: i64) -> Result { ... }
fn u64(&mut self, v: u64) -> Result { ... }
fn i128(&mut self, v: i128) -> Result { ... }
fn u128(&mut self, v: u128) -> Result { ... }
fn f64(&mut self, v: f64) -> Result { ... }
fn bool(&mut self, v: bool) -> Result { ... }
fn char(&mut self, v: char) -> Result { ... }
fn str(&mut self, v: &str) -> Result { ... }
fn none(&mut self) -> Result { ... }
fn map_begin(&mut self, len: Option<usize>) -> Result { ... }
fn map_key(&mut self) -> Result { ... }
fn map_value(&mut self) -> Result { ... }
fn map_end(&mut self) -> Result { ... }
fn seq_begin(&mut self, len: Option<usize>) -> Result { ... }
fn seq_elem(&mut self) -> Result { ... }
fn seq_end(&mut self) -> Result { ... } }

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 Values.

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::{self, 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::{self, 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::{self, 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::{self, Stream};

impl Stream for MyStream {
    fn fmt(&mut self, args: stream::Arguments) -> stream::Result {
        ..

        Ok(())
    }

    fn error(&mut self, source: stream::Source) -> 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, v: Arguments<'_>) -> Result[src]

Stream a debuggable type.

fn error(&mut self, v: Source<'_>) -> Result[src]

Stream an error.

fn i64(&mut self, v: i64) -> Result[src]

Stream a signed integer.

fn u64(&mut self, v: u64) -> Result[src]

Stream an unsigned integer.

fn i128(&mut self, v: i128) -> Result[src]

Stream a 128bit signed integer.

fn u128(&mut self, v: u128) -> Result[src]

Stream a 128bit unsigned integer.

fn f64(&mut self, v: f64) -> Result[src]

Stream a floating point value.

fn bool(&mut self, v: bool) -> Result[src]

Stream a boolean.

fn char(&mut self, v: char) -> Result[src]

Stream a unicode character.

fn str(&mut self, v: &str) -> Result[src]

Stream a UTF-8 string slice.

fn none(&mut self) -> Result[src]

Stream an empty value.

fn map_begin(&mut self, len: Option<usize>) -> Result[src]

Begin a map.

fn map_key(&mut self) -> Result[src]

Begin a map key.

The key will be implicitly ended by the stream methods that follow it.

fn map_value(&mut self) -> Result[src]

Begin a map value.

The value will be implicitly ended by the stream methods that follow it.

fn map_end(&mut self) -> Result[src]

End a map.

fn seq_begin(&mut self, len: Option<usize>) -> Result[src]

Begin a sequence.

fn seq_elem(&mut self) -> Result[src]

Begin a sequence element.

The element will be implicitly ended by the stream methods that follow it.

fn seq_end(&mut self) -> Result[src]

End a sequence.

Loading content...

Implementations on Foreign Types

impl<'a, T: ?Sized> Stream for &'a mut T where
    T: Stream
[src]

Loading content...

Implementors

impl Stream for Stack[src]

impl<'a> Stream for RefMutStream<'a>[src]

impl<S> Stream for OwnedStream<S> where
    S: Stream
[src]

Loading content...