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 11target
22Cargo.lock
33.vscode
4+ .idea
45* ~
56* .swp
Original file line number Diff line number Diff line change @@ -79,6 +79,12 @@ pub type Array = Vec<Bson>;
7979/// Alias for `OrderedDocument`.
8080pub type Document = OrderedDocument ;
8181
82+ impl Default for Bson {
83+ fn default ( ) -> Self {
84+ Bson :: Null
85+ }
86+ }
87+
8288impl Debug for Bson {
8389 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
8490 match self {
Original file line number Diff line number Diff line change @@ -60,6 +60,12 @@ pub struct OrderedDocument {
6060 inner : LinkedHashMap < String , Bson > ,
6161}
6262
63+ impl Default for OrderedDocument {
64+ fn default ( ) -> Self {
65+ Document :: new ( )
66+ }
67+ }
68+
6369impl Display for OrderedDocument {
6470 fn fmt ( & self , fmt : & mut Formatter ) -> fmt:: Result {
6571 try!( write ! ( fmt, "{{" ) ) ;
Original file line number Diff line number Diff line change 1+ extern crate serde_json;
2+
13use bson:: { Bson , Document } ;
4+ use self :: serde_json:: Value ;
25
36#[ test]
47fn to_json ( ) {
58 let mut doc = Document :: new ( ) ;
69 doc. insert ( "first" , Bson :: I32 ( 1 ) ) ;
710 doc. insert ( "second" , Bson :: String ( "foo" . to_owned ( ) ) ) ;
811 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 ( ) ;
1013
1114 assert ! ( data. is_object( ) ) ;
1215 let obj = data. as_object ( ) . unwrap ( ) ;
@@ -23,3 +26,16 @@ fn to_json() {
2326 assert ! ( alphanumeric. is_string( ) ) ;
2427 assert_eq ! ( alphanumeric. as_str( ) . unwrap( ) , "bar" ) ;
2528}
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-
41use std:: io:: Cursor ;
52use bson:: { Bson , decode_document, encode_document} ;
63use bson:: oid:: ObjectId ;
You can’t perform that action at this time.
0 commit comments