Skip to content

Commit 9b83c28

Browse files
committed
Removed Encoder in favor of free function.
1 parent 7c1e0eb commit 9b83c28

File tree

3 files changed

+169
-226
lines changed

3 files changed

+169
-226
lines changed

examples/encode.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ extern crate bson;
22
extern crate chrono;
33

44
use std::io::Cursor;
5-
use bson::{Bson, Document, Array, Encoder, Decoder};
5+
use bson::{Bson, Document, Array, encode_document, decode_document};
66

77
fn main() {
88
let mut doc = Document::new();
@@ -16,18 +16,11 @@ fn main() {
1616
doc.insert("array".to_string(), Bson::Array(arr));
1717

1818
let mut buf = Vec::new();
19-
{
20-
let mut enc = Encoder::new(&mut buf);
21-
enc.encode_document(&doc).unwrap();
22-
}
19+
encode_document(&mut buf, &doc).unwrap();
2320

2421
println!("Encoded: {:?}", buf);
2522

2623
let mut r = Cursor::new(&buf[..]);
27-
{
28-
let mut dec = Decoder::new(&mut r);
29-
let doc = dec.decode_document().unwrap();
30-
31-
println!("Decoded: {:?}", doc);
32-
}
24+
let doc = decode_document(&mut r).unwrap();
25+
println!("Decoded: {:?}", doc);
3326
}

0 commit comments

Comments
 (0)