File tree Expand file tree Collapse file tree 5 files changed +30
-4
lines changed Expand file tree Collapse file tree 5 files changed +30
-4
lines changed Original file line number Diff line number Diff line change 1
1
target
2
2
Cargo.lock
3
3
.vscode
4
+ .idea
4
5
* ~
5
6
* .swp
Original file line number Diff line number Diff line change @@ -79,6 +79,12 @@ pub type Array = Vec<Bson>;
79
79
/// Alias for `OrderedDocument`.
80
80
pub type Document = OrderedDocument ;
81
81
82
+ impl Default for Bson {
83
+ fn default ( ) -> Self {
84
+ Bson :: Null
85
+ }
86
+ }
87
+
82
88
impl Debug for Bson {
83
89
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
84
90
match self {
Original file line number Diff line number Diff line change @@ -60,6 +60,12 @@ pub struct OrderedDocument {
60
60
inner : LinkedHashMap < String , Bson > ,
61
61
}
62
62
63
+ impl Default for OrderedDocument {
64
+ fn default ( ) -> Self {
65
+ Document :: new ( )
66
+ }
67
+ }
68
+
63
69
impl Display for OrderedDocument {
64
70
fn fmt ( & self , fmt : & mut Formatter ) -> fmt:: Result {
65
71
try!( write ! ( fmt, "{{" ) ) ;
Original file line number Diff line number Diff line change
1
+ extern crate serde_json;
2
+
1
3
use bson:: { Bson , Document } ;
4
+ use self :: serde_json:: Value ;
2
5
3
6
#[ test]
4
7
fn to_json ( ) {
5
8
let mut doc = Document :: new ( ) ;
6
9
doc. insert ( "first" , Bson :: I32 ( 1 ) ) ;
7
10
doc. insert ( "second" , Bson :: String ( "foo" . to_owned ( ) ) ) ;
8
11
doc. insert ( "alphanumeric" , Bson :: String ( "bar" . to_owned ( ) ) ) ;
9
- let data = Bson :: Document ( doc) . to_json ( ) ;
12
+ let data: Value = Bson :: Document ( doc) . clone ( ) . into ( ) ;
10
13
11
14
assert ! ( data. is_object( ) ) ;
12
15
let obj = data. as_object ( ) . unwrap ( ) ;
@@ -23,3 +26,16 @@ fn to_json() {
23
26
assert ! ( alphanumeric. is_string( ) ) ;
24
27
assert_eq ! ( alphanumeric. as_str( ) . unwrap( ) , "bar" ) ;
25
28
}
29
+
30
+ #[ test]
31
+ fn bson_default ( ) {
32
+ let bson1 = Bson :: default ( ) ;
33
+ assert_eq ! ( bson1, Bson :: Null ) ;
34
+ }
35
+
36
+ #[ test]
37
+ fn document_default ( ) {
38
+ let doc1 = Document :: default ( ) ;
39
+ assert_eq ! ( doc1. keys( ) . count( ) , 0 ) ;
40
+ assert_eq ! ( doc1, Document :: new( ) ) ;
41
+ }
Original file line number Diff line number Diff line change 1
- extern crate bson;
2
- extern crate chrono;
3
-
4
1
use std:: io:: Cursor ;
5
2
use bson:: { Bson , decode_document, encode_document} ;
6
3
use bson:: oid:: ObjectId ;
You can’t perform that action at this time.
0 commit comments