@@ -4,7 +4,7 @@ use std::{
4
4
ops:: Deref ,
5
5
} ;
6
6
7
- use chrono :: { DateTime , Utc } ;
7
+ use crate :: DateTime ;
8
8
9
9
use super :: {
10
10
i32_from_slice,
@@ -130,8 +130,8 @@ impl RawDocument {
130
130
/// Element<'_>>`.
131
131
///
132
132
/// ```
133
- /// # use bson::raw::{elem, RawDocument, Error} ;
134
- /// use bson::doc;
133
+ /// # use bson::raw::Error;
134
+ /// use bson::{ doc, raw::RawDocument} ;
135
135
///
136
136
/// let doc = RawDocument::from_document(&doc! { "ferris": true });
137
137
///
@@ -218,7 +218,9 @@ impl ToOwned for RawDocumentRef {
218
218
/// original document without making any additional allocations.
219
219
220
220
/// ```
221
- /// # use bson::raw::{Doc, Error};
221
+ /// # use bson::raw::{Error};
222
+ /// use bson::raw::RawDocumentRef;
223
+ ///
222
224
/// let doc = RawDocumentRef::new(b"\x13\x00\x00\x00\x02hi\x00\x06\x00\x00\x00y'all\x00\x00")?;
223
225
/// let mut iter = doc.into_iter();
224
226
/// let (key, value) = iter.next().unwrap()?;
@@ -259,9 +261,10 @@ impl RawDocumentRef {
259
261
/// the RawDocument will return Errors where appropriate.
260
262
///
261
263
/// ```
262
- /// # use bson::raw::{RawDocument, Error};
264
+ /// use bson::raw::RawDocumentRef;
265
+ ///
263
266
/// let doc = RawDocumentRef::new(b"\x05\0\0\0\0")?;
264
- /// # Ok::<(), Error>(())
267
+ /// # Ok::<(), bson::raw:: Error>(())
265
268
/// ```
266
269
pub fn new < D : AsRef < [ u8 ] > + ?Sized > ( data : & D ) -> Result < & RawDocumentRef > {
267
270
let data = data. as_ref ( ) ;
@@ -306,8 +309,7 @@ impl RawDocumentRef {
306
309
/// Creates a new RawDocument with an owned copy of the BSON bytes.
307
310
///
308
311
/// ```
309
- /// # use bson::raw::{Doc, Error};
310
- /// use bson::raw::RawDocument;
312
+ /// use bson::raw::{RawDocumentRef, RawDocument, Error};
311
313
///
312
314
/// let data = b"\x05\0\0\0\0";
313
315
/// let doc_ref = RawDocumentRef::new(data)?;
@@ -323,9 +325,8 @@ impl RawDocumentRef {
323
325
/// found.
324
326
///
325
327
/// ```
326
- /// # use bson::raw::{RawDocument, elem::Element, Error};
327
- /// #
328
- /// use bson::{doc, oid::ObjectId};
328
+ /// # use bson::raw::Error;
329
+ /// use bson::{doc, oid::ObjectId, raw::{RawDocument, RawBson}};
329
330
///
330
331
/// let doc = RawDocument::from_document(&doc! {
331
332
/// "_id": ObjectId::new(),
@@ -359,7 +360,8 @@ impl RawDocumentRef {
359
360
/// if the key corresponds to a value which isn't a double.
360
361
///
361
362
/// ```
362
- /// # use bson::raw::{RawDocument, elem::Element, Error};
363
+ /// # use bson::raw::Error;
364
+ /// use bson::raw::RawDocument;
363
365
/// use bson::doc;
364
366
///
365
367
/// let doc = RawDocument::from_document(&doc! {
@@ -380,8 +382,7 @@ impl RawDocumentRef {
380
382
/// key corresponds to a value which isn't a string.
381
383
///
382
384
/// ```
383
- /// # use bson::raw::{RawDocument, elem::Element, Error};
384
- /// use bson::doc;
385
+ /// use bson::{doc, raw::{RawDocument, Error}};
385
386
///
386
387
/// let doc = RawDocument::from_document(&doc! {
387
388
/// "string": "hello",
@@ -401,8 +402,8 @@ impl RawDocumentRef {
401
402
/// the key corresponds to a value which isn't a document.
402
403
///
403
404
/// ```
404
- /// # use bson::raw::{RawDocument, elem::Element, Error} ;
405
- /// use bson::doc;
405
+ /// use bson::raw::Error;
406
+ /// use bson::{ doc, raw::RawDocument} ;
406
407
///
407
408
/// let doc = RawDocument::from_document(&doc! {
408
409
/// "doc": { "key": "value"},
@@ -422,17 +423,17 @@ impl RawDocumentRef {
422
423
/// the key corresponds to a value which isn't an array.
423
424
///
424
425
/// ```
425
- /// # use bson::raw::{RawDocument, elem::Element, Error} ;
426
- /// use bson::doc;
426
+ /// # use bson::raw::Error;
427
+ /// use bson::{ doc, raw::RawDocument} ;
427
428
///
428
429
/// let doc = RawDocument::from_document(&doc! {
429
430
/// "array": [true, 3],
430
431
/// "bool": true,
431
432
/// });
432
433
///
433
- /// let mut arr_iter = docbuf .get_array("array")?.expect("finding key array").into_iter();
434
- /// let _: bool = arriter .next().unwrap()?.as_bool()?;
435
- /// let _: i32 = arriter .next().unwrap()?.as_i32()?;
434
+ /// let mut arr_iter = doc .get_array("array")?.expect("finding key array").into_iter();
435
+ /// let _: bool = arr_iter .next().unwrap()?.as_bool()?;
436
+ /// let _: i32 = arr_iter .next().unwrap()?.as_i32()?;
436
437
///
437
438
/// assert!(arr_iter.next().is_none());
438
439
/// assert!(doc.get_array("bool").is_err());
@@ -447,19 +448,20 @@ impl RawDocumentRef {
447
448
/// if the key corresponds to a value which isn't a binary value.
448
449
///
449
450
/// ```
450
- /// # use bson::raw::{RawDocument, elem, Error};
451
- ///
451
+ /// # use bson::raw::Error;
452
452
/// use bson::{
453
- /// spec::BinarySubtype
454
- /// doc, Binary,
453
+ /// doc,
454
+ /// raw::{RawDocument, RawBinary},
455
+ /// spec::BinarySubtype,
456
+ /// Binary,
455
457
/// };
456
458
///
457
459
/// let doc = RawDocument::from_document(&doc! {
458
460
/// "binary": Binary { subtype: BinarySubtype::Generic, bytes: vec![1, 2, 3] },
459
461
/// "bool": true,
460
462
/// });
461
463
///
462
- /// assert_eq!(doc.get_binary("binary")?.map(elem::RawBsonBinary ::as_bytes), Some(&[1, 2, 3][..]));
464
+ /// assert_eq!(doc.get_binary("binary")?.map(RawBinary ::as_bytes), Some(&[1, 2, 3][..]));
463
465
/// assert_eq!(doc.get_binary("bool").unwrap_err(), Error::UnexpectedType);
464
466
/// assert!(doc.get_binary("unknown")?.is_none());
465
467
/// # Ok::<(), Error>(())
@@ -472,8 +474,8 @@ impl RawDocumentRef {
472
474
/// the key corresponds to a value which isn't an ObjectId.
473
475
///
474
476
/// ```
475
- /// # use bson::raw::{RawDocument, Error} ;
476
- /// use bson::{doc, oid::ObjectId};
477
+ /// # use bson::raw::Error;
478
+ /// use bson::{doc, oid::ObjectId, raw::RawDocument };
477
479
///
478
480
/// let doc = RawDocument::from_document(&doc! {
479
481
/// "_id": ObjectId::new(),
@@ -514,28 +516,28 @@ impl RawDocumentRef {
514
516
/// if the key corresponds to a value which isn't a DateTime.
515
517
///
516
518
/// ```
517
- /// # use bson::raw::{RawDocument, Error};
518
- /// use bson::doc;
519
- /// use chrono::{Utc, Datelike, TimeZone};
519
+ /// # use bson::raw::Error;
520
+ /// use bson::{doc, raw::RawDocument, DateTime};
520
521
///
522
+ /// let dt = DateTime::now();
521
523
/// let doc = RawDocument::from_document(&doc! {
522
- /// "created_at": Utc.ymd(2020, 3, 15).and_hms(17, 0, 0) ,
524
+ /// "created_at": dt ,
523
525
/// "bool": true,
524
526
/// });
525
- /// assert_eq!(doc.get_datetime("created_at")?.unwrap().year(), 2020 );
527
+ /// assert_eq!(doc.get_datetime("created_at")?, Some(dt) );
526
528
/// assert_eq!(doc.get_datetime("bool").unwrap_err(), Error::UnexpectedType);
527
529
/// assert!(doc.get_datetime("unknown")?.is_none());
528
530
/// # Ok::<(), Error>(())
529
531
/// ```
530
- pub fn get_datetime ( & self , key : & str ) -> Result < Option < DateTime < Utc > > > {
532
+ pub fn get_datetime ( & self , key : & str ) -> Result < Option < DateTime > > {
531
533
self . get_with ( key, RawBson :: as_datetime)
532
534
}
535
+
533
536
/// Gets a reference to the BSON regex value corresponding to a given key or returns an error if
534
537
/// the key corresponds to a value which isn't a regex.
535
538
///
536
539
/// ```
537
- /// # use bson::raw::{RawDocument, Error, elem};
538
- /// use bson::{doc, Regex};
540
+ /// use bson::{doc, Regex, raw::{RawDocument, Error}};
539
541
///
540
542
/// let doc = RawDocument::from_document(&doc! {
541
543
/// "regex": Regex {
@@ -559,8 +561,7 @@ impl RawDocumentRef {
559
561
/// error if the key corresponds to a value which isn't a timestamp.
560
562
///
561
563
/// ```
562
- /// # use bson::raw::{RawDocument, elem, Error};
563
- /// use bson::{doc, Timestamp};
564
+ /// use bson::{doc, Timestamp, raw::{RawDocument, Error}};
564
565
///
565
566
/// let doc = RawDocument::from_document(&doc! {
566
567
/// "bool": true,
@@ -604,8 +605,8 @@ impl RawDocumentRef {
604
605
/// the key corresponds to a value which isn't a 64-bit integer.
605
606
///
606
607
/// ```
607
- /// # use bson::raw::{RawDocument, elem::Element, Error} ;
608
- /// use bson::doc;
608
+ /// # use bson::raw::Error;
609
+ /// use bson::{ doc, raw::RawDocument} ;
609
610
///
610
611
/// let doc = RawDocument::from_document(&doc! {
611
612
/// "bool": true,
@@ -624,8 +625,8 @@ impl RawDocumentRef {
624
625
/// Return a reference to the contained data as a `&[u8]`
625
626
///
626
627
/// ```
627
- /// # use bson::raw::RawDocument ;
628
- /// use bson::doc;
628
+ /// # use bson::raw::Error ;
629
+ /// use bson::{ doc, raw::RawDocument} ;
629
630
/// let docbuf = RawDocument::from_document(&doc!{});
630
631
/// assert_eq!(docbuf.as_bytes(), b"\x05\x00\x00\x00\x00");
631
632
/// ```
0 commit comments