Skip to content

Commit a7dd92d

Browse files
authored
RUST-410 Rename OrderedDocument to Document (#168)
1 parent d84ea8c commit a7dd92d

File tree

4 files changed

+49
-51
lines changed

4 files changed

+49
-51
lines changed

src/bson.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ use serde_json::{json, Value};
3131

3232
#[cfg(feature = "decimal128")]
3333
use crate::decimal128::Decimal128;
34+
pub use crate::document::Document;
3435
use crate::{
3536
oid,
36-
ordered::OrderedDocument,
3737
spec::{BinarySubtype, ElementType},
3838
};
3939

@@ -87,8 +87,6 @@ pub enum Bson {
8787

8888
/// Alias for `Vec<Bson>`.
8989
pub type Array = Vec<Bson>;
90-
/// Alias for `OrderedDocument`.
91-
pub type Document = OrderedDocument;
9290

9391
impl Default for Bson {
9492
fn default() -> Self {

src/decoder/serde.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use super::error::{DecoderError, DecoderResult};
1919
use crate::decimal128::Decimal128;
2020
use crate::{
2121
bson::{Binary, Bson, DbPointer, JavaScriptCodeWithScope, Regex, TimeStamp, UtcDateTime},
22+
document::{Document, DocumentIntoIterator, DocumentVisitor},
2223
oid::ObjectId,
23-
ordered::{OrderedDocument, OrderedDocumentIntoIterator, OrderedDocumentVisitor},
2424
spec::BinarySubtype,
2525
};
2626

@@ -42,7 +42,7 @@ impl<'de> Deserialize<'de> for ObjectId {
4242
}
4343
}
4444

45-
impl<'de> Deserialize<'de> for OrderedDocument {
45+
impl<'de> Deserialize<'de> for Document {
4646
/// Deserialize this value given this `Deserializer`.
4747
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
4848
where
@@ -215,7 +215,7 @@ impl<'de> Visitor<'de> for BsonVisitor {
215215
where
216216
V: MapAccess<'de>,
217217
{
218-
let values = OrderedDocumentVisitor::new().visit_map(visitor)?;
218+
let values = DocumentVisitor::new().visit_map(visitor)?;
219219
Ok(Bson::from_extended_document(values))
220220
}
221221

@@ -591,7 +591,7 @@ impl<'de> SeqAccess<'de> for SeqDecoder {
591591
}
592592

593593
struct MapDecoder {
594-
iter: OrderedDocumentIntoIterator,
594+
iter: DocumentIntoIterator,
595595
value: Option<Bson>,
596596
len: usize,
597597
}

src/ordered.rs renamed to src/document.rs

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use serde::de::{self, MapAccess, Visitor};
1616
#[cfg(feature = "decimal128")]
1717
use crate::decimal128::Decimal128;
1818
use crate::{
19-
bson::{Array, Binary, Bson, Document, TimeStamp},
19+
bson::{Array, Binary, Bson, TimeStamp},
2020
oid::ObjectId,
2121
spec::BinarySubtype,
2222
};
@@ -62,17 +62,17 @@ impl error::Error for ValueAccessError {
6262

6363
/// A BSON document represented as an associative HashMap with insertion ordering.
6464
#[derive(Clone, PartialEq)]
65-
pub struct OrderedDocument {
65+
pub struct Document {
6666
inner: LinkedHashMap<String, Bson>,
6767
}
6868

69-
impl Default for OrderedDocument {
69+
impl Default for Document {
7070
fn default() -> Self {
7171
Document::new()
7272
}
7373
}
7474

75-
impl Display for OrderedDocument {
75+
impl Display for Document {
7676
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
7777
fmt.write_str("{")?;
7878

@@ -92,30 +92,30 @@ impl Display for OrderedDocument {
9292
}
9393
}
9494

95-
impl Debug for OrderedDocument {
95+
impl Debug for Document {
9696
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
97-
write!(f, "OrderedDocument({:?})", self.inner)
97+
write!(f, "Document({:?})", self.inner)
9898
}
9999
}
100100

101-
/// An iterator over OrderedDocument entries.
102-
pub struct OrderedDocumentIntoIterator {
101+
/// An iterator over Document entries.
102+
pub struct DocumentIntoIterator {
103103
inner: LinkedHashMap<String, Bson>,
104104
}
105105

106-
/// An owning iterator over OrderedDocument entries.
107-
pub struct OrderedDocumentIterator<'a> {
106+
/// An owning iterator over Document entries.
107+
pub struct DocumentIterator<'a> {
108108
inner: linked_hash_map::Iter<'a, String, Bson>,
109109
}
110110

111-
type DocumentMap<'a, T> = Map<OrderedDocumentIterator<'a>, fn((&'a String, &'a Bson)) -> T>;
111+
type DocumentMap<'a, T> = Map<DocumentIterator<'a>, fn((&'a String, &'a Bson)) -> T>;
112112

113-
/// An iterator over an OrderedDocument's keys.
113+
/// An iterator over an Document's keys.
114114
pub struct Keys<'a> {
115115
inner: DocumentMap<'a, &'a String>,
116116
}
117117

118-
/// An iterator over an OrderedDocument's values.
118+
/// An iterator over an Document's values.
119119
pub struct Values<'a> {
120120
inner: DocumentMap<'a, &'a Bson>,
121121
}
@@ -136,62 +136,62 @@ impl<'a> Iterator for Values<'a> {
136136
}
137137
}
138138

139-
impl IntoIterator for OrderedDocument {
139+
impl IntoIterator for Document {
140140
type Item = (String, Bson);
141-
type IntoIter = OrderedDocumentIntoIterator;
141+
type IntoIter = DocumentIntoIterator;
142142

143143
fn into_iter(self) -> Self::IntoIter {
144-
OrderedDocumentIntoIterator { inner: self.inner }
144+
DocumentIntoIterator { inner: self.inner }
145145
}
146146
}
147147

148-
impl<'a> IntoIterator for &'a OrderedDocument {
148+
impl<'a> IntoIterator for &'a Document {
149149
type Item = (&'a String, &'a Bson);
150-
type IntoIter = OrderedDocumentIterator<'a>;
150+
type IntoIter = DocumentIterator<'a>;
151151

152152
fn into_iter(self) -> Self::IntoIter {
153-
OrderedDocumentIterator {
153+
DocumentIterator {
154154
inner: self.inner.iter(),
155155
}
156156
}
157157
}
158158

159-
impl FromIterator<(String, Bson)> for OrderedDocument {
159+
impl FromIterator<(String, Bson)> for Document {
160160
fn from_iter<T: IntoIterator<Item = (String, Bson)>>(iter: T) -> Self {
161-
let mut doc = OrderedDocument::new();
161+
let mut doc = Document::new();
162162
for (k, v) in iter {
163163
doc.insert(k, v);
164164
}
165165
doc
166166
}
167167
}
168168

169-
impl<'a> Iterator for OrderedDocumentIntoIterator {
169+
impl<'a> Iterator for DocumentIntoIterator {
170170
type Item = (String, Bson);
171171

172172
fn next(&mut self) -> Option<(String, Bson)> {
173173
self.inner.pop_front()
174174
}
175175
}
176176

177-
impl<'a> Iterator for OrderedDocumentIterator<'a> {
177+
impl<'a> Iterator for DocumentIterator<'a> {
178178
type Item = (&'a String, &'a Bson);
179179

180180
fn next(&mut self) -> Option<(&'a String, &'a Bson)> {
181181
self.inner.next()
182182
}
183183
}
184184

185-
impl OrderedDocument {
186-
/// Creates a new empty OrderedDocument.
187-
pub fn new() -> OrderedDocument {
188-
OrderedDocument {
185+
impl Document {
186+
/// Creates a new empty Document.
187+
pub fn new() -> Document {
188+
Document {
189189
inner: LinkedHashMap::new(),
190190
}
191191
}
192192

193193
/// Gets an iterator over the entries of the map.
194-
pub fn iter(&self) -> OrderedDocumentIterator {
194+
pub fn iter(&self) -> DocumentIterator {
195195
self.into_iter()
196196
}
197197

@@ -526,42 +526,42 @@ impl<'a> Entry<'a> {
526526
}
527527
}
528528

529-
impl From<LinkedHashMap<String, Bson>> for OrderedDocument {
530-
fn from(tree: LinkedHashMap<String, Bson>) -> OrderedDocument {
531-
OrderedDocument { inner: tree }
529+
impl From<LinkedHashMap<String, Bson>> for Document {
530+
fn from(tree: LinkedHashMap<String, Bson>) -> Document {
531+
Document { inner: tree }
532532
}
533533
}
534534

535-
pub struct OrderedDocumentVisitor {
536-
marker: PhantomData<OrderedDocument>,
535+
pub struct DocumentVisitor {
536+
marker: PhantomData<Document>,
537537
}
538538

539-
impl OrderedDocumentVisitor {
539+
impl DocumentVisitor {
540540
#[allow(clippy::new_without_default)]
541-
pub fn new() -> OrderedDocumentVisitor {
542-
OrderedDocumentVisitor {
541+
pub fn new() -> DocumentVisitor {
542+
DocumentVisitor {
543543
marker: PhantomData,
544544
}
545545
}
546546
}
547547

548-
impl<'de> Visitor<'de> for OrderedDocumentVisitor {
549-
type Value = OrderedDocument;
548+
impl<'de> Visitor<'de> for DocumentVisitor {
549+
type Value = Document;
550550

551551
fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result {
552552
write!(f, "expecting ordered document")
553553
}
554554

555555
#[inline]
556-
fn visit_unit<E>(self) -> Result<OrderedDocument, E>
556+
fn visit_unit<E>(self) -> Result<Document, E>
557557
where
558558
E: de::Error,
559559
{
560-
Ok(OrderedDocument::new())
560+
Ok(Document::new())
561561
}
562562

563563
#[inline]
564-
fn visit_map<V>(self, mut visitor: V) -> Result<OrderedDocument, V::Error>
564+
fn visit_map<V>(self, mut visitor: V) -> Result<Document, V::Error>
565565
where
566566
V: MapAccess<'de>,
567567
{
@@ -578,7 +578,7 @@ impl<'de> Visitor<'de> for OrderedDocumentVisitor {
578578
}
579579
}
580580

581-
impl Extend<(String, Bson)> for OrderedDocument {
581+
impl Extend<(String, Bson)> for Document {
582582
fn extend<T: IntoIterator<Item = (String, Bson)>>(&mut self, iter: T) {
583583
for (k, v) in iter {
584584
self.insert(k, v);

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ pub use self::{
6161
DecoderError,
6262
DecoderResult,
6363
},
64+
document::{ValueAccessError, ValueAccessResult},
6465
encoder::{encode_document, to_bson, Encoder, EncoderError, EncoderResult},
65-
ordered::{ValueAccessError, ValueAccessResult},
6666
};
6767

6868
#[macro_use]
@@ -72,7 +72,7 @@ pub mod compat;
7272
#[cfg(feature = "decimal128")]
7373
pub mod decimal128;
7474
mod decoder;
75+
pub mod document;
7576
mod encoder;
7677
pub mod oid;
77-
pub mod ordered;
7878
pub mod spec;

0 commit comments

Comments
 (0)