File tree Expand file tree Collapse file tree 2 files changed +12
-5
lines changed Expand file tree Collapse file tree 2 files changed +12
-5
lines changed Original file line number Diff line number Diff line change
1
+ rocket in the sky, don't ask me why
2
+
Original file line number Diff line number Diff line change @@ -16,9 +16,14 @@ This crate works with Cargo and can be found on
16
16
17
17
``` toml
18
18
[dependencies ]
19
- bson = " * "
19
+ bson = " 0.3.2 "
20
20
```
21
21
## Usage
22
+ Link the library in _ main.rs_ :
23
+ ``` rust
24
+ #[macro_use(bson, doc)]
25
+ extern crate bson;
26
+ ```
22
27
23
28
Prepare your struct for Serde serialization:
24
29
``` rust
@@ -42,19 +47,19 @@ let person = Person {
42
47
};
43
48
44
49
let serialized_person = bson :: to_bson (& person )? ; // Serialize
45
-
46
- if let bson :: Bson :: Document (document ) = serialized {
50
+
51
+ if let bson :: Bson :: Document (document ) = serialized_person {
47
52
mongoCollection. insert_one (document , None )? ; // Insert into a MongoDB collection
48
53
} else {
49
- println! (" Error converting the BSON object into a MongoDB document" )
54
+ println! (" Error converting the BSON object into a MongoDB document" );
50
55
}
51
56
```
52
57
53
58
Deserialize the struct:
54
59
``` rust
55
60
// Read the document from a MongoDB collection
56
61
let person_document = mongoCollection. find_one (Some (doc! { " _id" => " 12345" }), None )?
57
- . expect (" Document not found" )
62
+ . expect (" Document not found" );
58
63
59
64
// Deserialize the document into a Person instance
60
65
let person = bson :: from_bson (bson :: Bson :: Document (person_document ))?
You can’t perform that action at this time.
0 commit comments