rust-sen/sehn/examples/basic.rs

39 lines
835 B
Rust
Raw Normal View History

2019-01-20 14:26:37 +00:00
extern crate sehn;
use std::collections::BTreeMap;
use sehn::*;
2019-01-21 13:34:59 +00:00
fn print_and_clear(s: BaseSerializer<DefaultConfig, &mut GenericBufferWriter<Vec<u8>>>) {
2019-01-20 14:26:37 +00:00
let out = s.into_inner();
println!("{}", out.as_str());
2019-01-20 14:26:37 +00:00
out.clear();
}
fn main() {
2019-01-21 13:34:59 +00:00
let mut w = GenericBufferWriter::from(Vec::new());
2019-01-20 14:26:37 +00:00
///////////////////////////////////////////////////////////////////////////
let mut s = BaseSerializer::new(&mut w);
2019-01-20 14:26:37 +00:00
let mut obj = BTreeMap::new();
obj.insert("hello", Tag::new("one", vec![1]));
obj.insert("world", Tag::new("two", vec![2]));
s.serialize_any(obj).unwrap();
print_and_clear(s);
///////////////////////////////////////////////////////////////////////////
let mut s = BaseSerializer::new(&mut w);
2019-01-20 14:26:37 +00:00
let lines = vec![
"hello",
"world"
];
s.serialize_multiline_text(lines).unwrap();
print_and_clear(s);
}