Skip to content

Commit df16657

Browse files
authored
minor: Fix code snippet in README (#198)
1 parent 0cf6874 commit df16657

File tree

2 files changed

+44
-49
lines changed

2 files changed

+44
-49
lines changed

README.md

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -154,33 +154,31 @@ e.g.:
154154
#[derive(Serialize, Deserialize)]
155155
struct Person {
156156
name: String,
157-
age: u8,
157+
age: i32,
158158
phones: Vec<String>,
159159
}
160160

161-
fn typed_example() {
162-
// Some BSON input data as a `Bson`.
163-
let bson_data: Bson = bson!({
164-
"name": "John Doe",
165-
"age": 43,
166-
"phones": [
167-
"+44 1234567",
168-
"+44 2345678"
169-
]
170-
});
171-
172-
// Deserialize the Person struct from the BSON data, automatically
173-
// verifying that the necessary keys are present and that they are of
174-
// the correct types.
175-
let mut person: Person = bson::from_bson(bson_data).unwrap();
176-
177-
// Do things just like with any other Rust data structure.
178-
println!("Redacting {}'s record.", person.name);
179-
person.name = "REDACTED".to_string();
180-
181-
// Get a serialized version of the input data as a `Bson`.
182-
let redacted_bson = bson::to_bson(&person).unwrap();
183-
}
161+
// Some BSON input data as a `Bson`.
162+
let bson_data: Bson = bson!({
163+
"name": "John Doe",
164+
"age": 43,
165+
"phones": [
166+
"+44 1234567",
167+
"+44 2345678"
168+
]
169+
});
170+
171+
// Deserialize the Person struct from the BSON data, automatically
172+
// verifying that the necessary keys are present and that they are of
173+
// the correct types.
174+
let mut person: Person = bson::from_bson(bson_data).unwrap();
175+
176+
// Do things just like with any other Rust data structure.
177+
println!("Redacting {}'s record.", person.name);
178+
person.name = "REDACTED".to_string();
179+
180+
// Get a serialized version of the input data as a `Bson`.
181+
let redacted_bson = bson::to_bson(&person).unwrap();
184182
```
185183

186184
Any types that implement `Serialize` and `Deserialize` can be used in this way. Doing so helps
@@ -241,4 +239,3 @@ bash .evergreen/check-clippy.sh && bash .evergreen/check-rustfmt.sh
241239

242240
## Continuous Integration
243241
Commits to master are run automatically on [evergreen](https://evergreen.mongodb.com/waterfall/rust-bson).
244-

src/lib.rs

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -150,33 +150,31 @@
150150
//! #[derive(Serialize, Deserialize)]
151151
//! struct Person {
152152
//! name: String,
153-
//! age: u8,
153+
//! age: i32,
154154
//! phones: Vec<String>,
155155
//! }
156156
//!
157-
//! fn typed_example() {
158-
//! // Some BSON input data as a `Bson`.
159-
//! let bson_data: Bson = bson!({
160-
//! "name": "John Doe",
161-
//! "age": 43,
162-
//! "phones": [
163-
//! "+44 1234567",
164-
//! "+44 2345678"
165-
//! ]
166-
//! });
167-
//!
168-
//! // Deserialize the Person struct from the BSON data, automatically
169-
//! // verifying that the necessary keys are present and that they are of
170-
//! // the correct types.
171-
//! let mut person: Person = bson::from_bson(bson_data).unwrap();
172-
//!
173-
//! // Do things just like with any other Rust data structure.
174-
//! println!("Redacting {}'s record.", person.name);
175-
//! person.name = "REDACTED".to_string();
176-
//!
177-
//! // Get a serialized version of the input data as a `Bson`.
178-
//! let redacted_bson = bson::to_bson(&person).unwrap();
179-
//! }
157+
//! // Some BSON input data as a `Bson`.
158+
//! let bson_data: Bson = bson!({
159+
//! "name": "John Doe",
160+
//! "age": 43,
161+
//! "phones": [
162+
//! "+44 1234567",
163+
//! "+44 2345678"
164+
//! ]
165+
//! });
166+
//!
167+
//! // Deserialize the Person struct from the BSON data, automatically
168+
//! // verifying that the necessary keys are present and that they are of
169+
//! // the correct types.
170+
//! let mut person: Person = bson::from_bson(bson_data).unwrap();
171+
//!
172+
//! // Do things just like with any other Rust data structure.
173+
//! println!("Redacting {}'s record.", person.name);
174+
//! person.name = "REDACTED".to_string();
175+
//!
176+
//! // Get a serialized version of the input data as a `Bson`.
177+
//! let redacted_bson = bson::to_bson(&person).unwrap();
180178
//! ```
181179
//!
182180
//! Any types that implement `Serialize` and `Deserialize` can be used in this way. Doing so helps

0 commit comments

Comments
 (0)