data-stream 0.3.1

A simple serialization library based on streams
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
use std::{fmt::Debug, io::Result};

use data_stream::{FromStream, ToStream, from_stream, to_stream};

pub fn try_streaming<S, V: ToStream<S> + FromStream<S>>(value: &V) -> Result<V> {
    let mut bytes = Vec::new();
    to_stream(value, &mut &mut bytes)?;
    from_stream(&mut &bytes[..])
}

pub fn assert_streamed_eq<S, V: ToStream<S> + FromStream<S> + PartialEq + Debug>(value: &V) {
    let copy = try_streaming(value).unwrap();
    assert_eq!(value, &copy);
}