Skip to content

Commit 007137f

Browse files
committed
rename RawDoc -> RawDocument, RawDocument -> RawDocumentBuf
1 parent 91179d5 commit 007137f

File tree

11 files changed

+735
-729
lines changed

11 files changed

+735
-729
lines changed

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ pub use self::{
317317
Deserializer,
318318
},
319319
decimal128::Decimal128,
320+
raw::{RawDocument, RawDocumentBuf, RawArray},
320321
ser::{to_bson, to_document, to_vec, Serializer},
321322
};
322323

src/raw/array.rs

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,33 @@ use super::{
66
Iter,
77
RawBinary,
88
RawBson,
9-
RawDoc,
9+
RawDocument,
1010
RawRegex,
1111
Result,
1212
};
1313
use crate::{oid::ObjectId, spec::ElementType, Bson, DateTime, Timestamp};
1414

1515
/// A slice of a BSON document containing a BSON array value (akin to [`std::str`]). This can be
16-
/// retrieved from a [`RawDoc`] via [`RawDoc::get`].
16+
/// retrieved from a [`RawDocument`] via [`RawDocument::get`].
1717
///
1818
/// This is an _unsized_ type, meaning that it must always be used behind a pointer like `&`.
1919
///
20-
/// Accessing elements within a [`RawArr`] is similar to element access in [`crate::Document`],
20+
/// Accessing elements within a [`RawArray`] is similar to element access in [`crate::Document`],
2121
/// but because the contents are parsed during iteration instead of at creation time, format errors
2222
/// can happen at any time during use.
2323
///
24-
/// Iterating over a [`RawArr`] yields either an error or a value that borrows from the
24+
/// Iterating over a [`RawArray`] yields either an error or a value that borrows from the
2525
/// original document without making any additional allocations.
2626
///
2727
/// ```
28-
/// use bson::{doc, raw::RawDoc};
28+
/// use bson::{doc, raw::RawDocument};
2929
///
3030
/// let doc = doc! {
3131
/// "x": [1, true, "two", 5.5]
3232
/// };
3333
/// let bytes = bson::to_vec(&doc)?;
3434
///
35-
/// let rawdoc = RawDoc::new(bytes.as_slice())?;
35+
/// let rawdoc = RawDocument::new(bytes.as_slice())?;
3636
/// let rawarray = rawdoc.get_array("x")?;
3737
///
3838
/// for v in rawarray {
@@ -41,44 +41,44 @@ use crate::{oid::ObjectId, spec::ElementType, Bson, DateTime, Timestamp};
4141
/// # Ok::<(), Box<dyn std::error::Error>>(())
4242
/// ```
4343
///
44-
/// Individual elements can be accessed using [`RawArr::get`] or any of
45-
/// the type-specific getters, such as [`RawArr::get_object_id`] or
46-
/// [`RawArr::get_str`]. Note that accessing elements is an O(N) operation, as it
44+
/// Individual elements can be accessed using [`RawArray::get`] or any of
45+
/// the type-specific getters, such as [`RawArray::get_object_id`] or
46+
/// [`RawArray::get_str`]. Note that accessing elements is an O(N) operation, as it
4747
/// requires iterating through the array from the beginning to find the requested index.
4848
///
4949
/// ```
5050
/// # use bson::raw::{ValueAccessError};
51-
/// use bson::{doc, raw::RawDoc};
51+
/// use bson::{doc, raw::RawDocument};
5252
///
5353
/// let doc = doc! {
5454
/// "x": [1, true, "two", 5.5]
5555
/// };
5656
/// let bytes = bson::to_vec(&doc)?;
5757
///
58-
/// let rawdoc = RawDoc::new(bytes.as_slice())?;
58+
/// let rawdoc = RawDocument::new(bytes.as_slice())?;
5959
/// let rawarray = rawdoc.get_array("x")?;
6060
///
6161
/// assert_eq!(rawarray.get_bool(1)?, true);
6262
/// # Ok::<(), Box<dyn std::error::Error>>(())
6363
/// ```
6464
#[derive(PartialEq)]
6565
#[repr(transparent)]
66-
pub struct RawArr {
67-
pub(crate) doc: RawDoc,
66+
pub struct RawArray {
67+
pub(crate) doc: RawDocument,
6868
}
6969

70-
impl RawArr {
71-
pub(crate) fn from_doc(doc: &RawDoc) -> &RawArr {
70+
impl RawArray {
71+
pub(crate) fn from_doc(doc: &RawDocument) -> &RawArray {
7272
// SAFETY:
7373
//
7474
// Dereferencing a raw pointer requires unsafe due to the potential that the pointer is
7575
// null, dangling, or misaligned. We know the pointer is not null or dangling due to the
76-
// fact that it's created by a safe reference. Converting &RawDoc to *const
77-
// RawDoc will be properly aligned due to them being references to the same type,
78-
// and converting *const RawDoc to *const RawArr is aligned due to the fact that
79-
// the only field in a RawArr is a RawDoc, meaning the structs are represented
76+
// fact that it's created by a safe reference. Converting &RawDocument to *const
77+
// RawDocument will be properly aligned due to them being references to the same type,
78+
// and converting *const RawDocument to *const RawArray is aligned due to the fact that
79+
// the only field in a RawArray is a RawDocument, meaning the structs are represented
8080
// identically at the byte level.
81-
unsafe { &*(doc as *const RawDoc as *const RawArr) }
81+
unsafe { &*(doc as *const RawDocument as *const RawArray) }
8282
}
8383

8484
/// Gets a reference to the value at the given index.
@@ -128,13 +128,13 @@ impl RawArr {
128128

129129
/// Gets a reference to the document at the given index or returns an error if the
130130
/// value at that index isn't a document.
131-
pub fn get_document(&self, index: usize) -> ValueAccessResult<&RawDoc> {
131+
pub fn get_document(&self, index: usize) -> ValueAccessResult<&RawDocument> {
132132
self.get_with(index, ElementType::EmbeddedDocument, RawBson::as_document)
133133
}
134134

135135
/// Gets a reference to the array at the given index or returns an error if the
136136
/// value at that index isn't a array.
137-
pub fn get_array(&self, index: usize) -> ValueAccessResult<&RawArr> {
137+
pub fn get_array(&self, index: usize) -> ValueAccessResult<&RawArray> {
138138
self.get_with(index, ElementType::Array, RawBson::as_array)
139139
}
140140

@@ -186,24 +186,24 @@ impl RawArr {
186186
self.get_with(index, ElementType::Int64, RawBson::as_i64)
187187
}
188188

189-
/// Gets a reference to the raw bytes of the RawArr.
189+
/// Gets a reference to the raw bytes of the [`RawArray`].
190190
pub fn as_bytes(&self) -> &[u8] {
191191
self.doc.as_bytes()
192192
}
193193
}
194194

195-
impl std::fmt::Debug for RawArr {
195+
impl std::fmt::Debug for RawArray {
196196
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
197-
f.debug_struct("RawArr")
197+
f.debug_struct("RawArray")
198198
.field("data", &hex::encode(self.doc.as_bytes()))
199199
.finish()
200200
}
201201
}
202202

203-
impl TryFrom<&RawArr> for Vec<Bson> {
203+
impl TryFrom<&RawArray> for Vec<Bson> {
204204
type Error = Error;
205205

206-
fn try_from(arr: &RawArr) -> Result<Vec<Bson>> {
206+
fn try_from(arr: &RawArray) -> Result<Vec<Bson>> {
207207
arr.into_iter()
208208
.map(|result| {
209209
let rawbson = result?;
@@ -213,23 +213,23 @@ impl TryFrom<&RawArr> for Vec<Bson> {
213213
}
214214
}
215215

216-
impl<'a> IntoIterator for &'a RawArr {
217-
type IntoIter = RawArrIter<'a>;
216+
impl<'a> IntoIterator for &'a RawArray {
217+
type IntoIter = RawArrayIter<'a>;
218218
type Item = Result<RawBson<'a>>;
219219

220-
fn into_iter(self) -> RawArrIter<'a> {
221-
RawArrIter {
220+
fn into_iter(self) -> RawArrayIter<'a> {
221+
RawArrayIter {
222222
inner: self.doc.into_iter(),
223223
}
224224
}
225225
}
226226

227227
/// An iterator over borrowed raw BSON array values.
228-
pub struct RawArrIter<'a> {
228+
pub struct RawArrayIter<'a> {
229229
inner: Iter<'a>,
230230
}
231231

232-
impl<'a> Iterator for RawArrIter<'a> {
232+
impl<'a> Iterator for RawArrayIter<'a> {
233233
type Item = Result<RawBson<'a>>;
234234

235235
fn next(&mut self) -> Option<Result<RawBson<'a>>> {

src/raw/bson.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::convert::{TryFrom, TryInto};
22

3-
use super::{Error, RawArr, RawDoc, Result};
3+
use super::{Error, RawArray, RawDocument, Result};
44
use crate::{
55
oid::{self, ObjectId},
66
spec::{BinarySubtype, ElementType},
@@ -18,9 +18,9 @@ pub enum RawBson<'a> {
1818
/// UTF-8 string
1919
String(&'a str),
2020
/// Array
21-
Array(&'a RawArr),
21+
Array(&'a RawArray),
2222
/// Embedded document
23-
Document(&'a RawDoc),
23+
Document(&'a RawDocument),
2424
/// Boolean value
2525
Boolean(bool),
2626
/// Null value
@@ -103,18 +103,18 @@ impl<'a> RawBson<'a> {
103103
}
104104
}
105105

106-
/// Gets the [`crate::raw::RawArr`] that's referenced or returns `None` if the referenced value
106+
/// Gets the [`RawArray`] that's referenced or returns `None` if the referenced value
107107
/// isn't a BSON array.
108-
pub fn as_array(self) -> Option<&'a RawArr> {
108+
pub fn as_array(self) -> Option<&'a RawArray> {
109109
match self {
110110
RawBson::Array(v) => Some(v),
111111
_ => None,
112112
}
113113
}
114114

115-
/// Gets the [`crate::raw::RawDoc`] that's referenced or returns `None` if the referenced value
115+
/// Gets the [`RawDocument`] that's referenced or returns `None` if the referenced value
116116
/// isn't a BSON document.
117-
pub fn as_document(self) -> Option<&'a RawDoc> {
117+
pub fn as_document(self) -> Option<&'a RawDocument> {
118118
match self {
119119
RawBson::Document(v) => Some(v),
120120
_ => None,
@@ -341,7 +341,7 @@ impl<'a> RawRegex<'a> {
341341
#[derive(Clone, Copy, Debug, PartialEq)]
342342
pub struct RawJavaScriptCodeWithScope<'a> {
343343
pub(crate) code: &'a str,
344-
pub(crate) scope: &'a RawDoc,
344+
pub(crate) scope: &'a RawDocument,
345345
}
346346

347347
impl<'a> RawJavaScriptCodeWithScope<'a> {
@@ -351,7 +351,7 @@ impl<'a> RawJavaScriptCodeWithScope<'a> {
351351
}
352352

353353
/// Gets the scope in the value.
354-
pub fn scope(self) -> &'a RawDoc {
354+
pub fn scope(self) -> &'a RawDocument {
355355
self.scope
356356
}
357357
}

0 commit comments

Comments
 (0)