Skip to content

Commit 10de77d

Browse files
committed
[#35, #33] use linked-hash-map, make ordered module public
1 parent adbbc97 commit 10de77d

File tree

4 files changed

+126
-109
lines changed

4 files changed

+126
-109
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ rust-crypto = "0.2.31"
1919
rustc-serialize = "0.3"
2020
serde = "0.7"
2121
time = "0.1"
22+
linked-hash-map = "0.0.9"
2223

2324
[dependencies.num]
2425
version = "~0.1.27"

src/decoder/serde.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use serde::de::{self, Deserialize, Deserializer, Visitor,
55

66
use bson::Bson;
77
use oid::ObjectId;
8-
use ordered::{OrderedDocument, OrderedDocumentIntoIterator};
8+
use ordered::{OrderedDocument, OrderedDocumentIntoIterator, OrderedDocumentVisitor};
99
use super::error::{DecoderError, DecoderResult};
1010

1111
pub struct BsonVisitor;
@@ -49,7 +49,7 @@ impl Deserialize for Bson {
4949

5050
impl Visitor for BsonVisitor {
5151
type Value = Bson;
52-
52+
5353
#[inline]
5454
fn visit_bool<E>(&mut self, value: bool) -> Result<Bson, E> {
5555
Ok(Bson::Boolean(value))
@@ -66,7 +66,7 @@ impl Visitor for BsonVisitor {
6666
Ok(Bson::I32(value as i32))
6767
}
6868

69-
69+
7070
#[inline]
7171
fn visit_i32<E>(&mut self, value: i32) -> Result<Bson, E> {
7272
Ok(Bson::I32(value))
@@ -76,59 +76,59 @@ impl Visitor for BsonVisitor {
7676
fn visit_i64<E>(&mut self, value: i64) -> Result<Bson, E> {
7777
Ok(Bson::I64(value))
7878
}
79-
79+
8080
#[inline]
8181
fn visit_u64<E>(&mut self, value: u64) -> Result<Bson, E> {
8282
Ok(Bson::I64(value as i64))
8383
}
84-
84+
8585
#[inline]
8686
fn visit_f64<E>(&mut self, value: f64) -> Result<Bson, E> {
8787
Ok(Bson::FloatingPoint(value))
8888
}
89-
89+
9090
#[inline]
9191
fn visit_str<E>(&mut self, value: &str) -> Result<Bson, E>
9292
where E: de::Error
9393
{
9494
self.visit_string(String::from(value))
9595
}
96-
96+
9797
#[inline]
9898
fn visit_string<E>(&mut self, value: String) -> Result<Bson, E> {
9999
Ok(Bson::String(value))
100100
}
101-
101+
102102
#[inline]
103103
fn visit_none<E>(&mut self) -> Result<Bson, E> {
104104
Ok(Bson::Null)
105105
}
106-
106+
107107
#[inline]
108108
fn visit_some<D>(&mut self, deserializer: &mut D) -> Result<Bson, D::Error>
109109
where D: Deserializer,
110110
{
111111
de::Deserialize::deserialize(deserializer)
112112
}
113-
113+
114114
#[inline]
115115
fn visit_unit<E>(&mut self) -> Result<Bson, E> {
116116
Ok(Bson::Null)
117117
}
118-
118+
119119
#[inline]
120120
fn visit_seq<V>(&mut self, visitor: V) -> Result<Bson, V::Error>
121121
where V: SeqVisitor,
122122
{
123123
let values = try!(de::impls::VecVisitor::new().visit_seq(visitor));
124124
Ok(Bson::Array(values))
125125
}
126-
126+
127127
#[inline]
128128
fn visit_map<V>(&mut self, visitor: V) -> Result<Bson, V::Error>
129129
where V: MapVisitor,
130130
{
131-
let values = try!(de::impls::BTreeMapVisitor::new().visit_map(visitor));
131+
let values = try!(OrderedDocumentVisitor::new().visit_map(visitor));
132132
Ok(Bson::from_extended_document(values.into()))
133133
}
134134
}

src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ extern crate rand;
5050
extern crate rustc_serialize;
5151
extern crate serde;
5252
extern crate time;
53+
extern crate linked_hash_map;
5354

5455
pub use self::bson::{Bson, Document, Array};
5556
pub use self::encoder::{encode_document, to_bson, Encoder, EncoderResult, EncoderError};
@@ -63,4 +64,4 @@ pub mod spec;
6364
mod bson;
6465
mod encoder;
6566
mod decoder;
66-
mod ordered;
67+
pub mod ordered;

0 commit comments

Comments
 (0)