Module destream::en[][src]

Expand description

Streaming serialization framework based on serde::ser.

The two most important traits in this module are ToStream and Encoder.

  • A type that implements ToStream is a data structure that can be encoded to any stream format supported by destream, and conversely
  • A type that implements Encoder is a data format that can encode any supported data structure into a stream.

The ToStream trait

destream provides ToStream implementations for many Rust primitive and standard library types. The complete list is below. All of these can be encoded automatically using destream.

Implementations of ToStream provided by destream

  • Primitive types:
    • bool
    • i8, i16, i32, i64, i128, isize
    • u8, u16, u32, u64, u128, usize
    • f32, f64
    • str
    • &T and &mut T
  • Compound types:
    • [T]
    • [T; 0] through [T; 32]
    • tuples up to size 16
  • Common standard library types:
    • String
    • Option<T>
    • Result<T, E>
    • PhantomData<T>
  • Other common types:
    • Bytes
  • Wrapper types:
    • Box<T>
  • Collection types:
    • BTreeMap<K, V>
    • BTreeSet<T>
    • BinaryHeap<T>
    • HashMap<K, V, H>
    • HashSet<T, H>
    • LinkedList<T>
    • VecDeque<T>
    • Vec<T>

The IntoStream trait

Often when encoding a stream, a value needs to be encoded which may outlive the calling function context. For this reason, the encode_map, encode_seq, and encode_stream methods accept a value which implements IntoStream. A borrow of a ToStream value automatically implements IntoStream, so you can still call encode_* on a borrowed value, but with the advantage that you can also encode an owned value into a stream of any lifetime by implementing IntoStream.

Implementations of IntoStream provided by destream

  • All ToStream types above, except [T; 0] through [T; 32]
  • &T and &mut T
  • MapStream<Item = Result<(K, V), E>>
  • SeqStream<Item = Result<T, E>>

Structs

Disambiguates a map from a sequence when encoding a stream.

Disambiguates a sequence from a map when encoding a stream.

Traits

Returned from Encoder::encode_map.

Returned from Encoder::encode_seq.

Returned from Encoder::encode_tuple.

A data format that can encode and stream any data structure supported by destream.

A data structure that can be serialized into any supported stream encoding.

A data structure which can be borrowed to serialize into any supported stream encoding.