Skip to content
This repository was archived by the owner on Oct 18, 2021. It is now read-only.

Commit b5d1476

Browse files
authored
Update bson to 0.6.0 (#200)
1 parent e3626f7 commit b5d1476

File tree

7 files changed

+43
-43
lines changed

7 files changed

+43
-43
lines changed

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ license = "Apache-2.0"
77
name = "mongodb"
88
readme = "README.md"
99
repository = "https://github.com/mongodb-labs/mongo-rust-driver-prototype"
10-
version = "0.2.3"
10+
version = "0.2.4"
1111

1212
[dependencies]
1313
bitflags = "0.7.0"
14-
bson = "0.4.4"
14+
bson = "0.6.0"
1515
bufstream = "0.1.1"
1616
byteorder = "0.5.3"
1717
chrono = "0.2.25"

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ The driver is available on crates.io. To use the MongoDB driver in your code, ad
2222

2323
```
2424
[dependencies]
25-
bson = "0.4.4"
26-
mongodb = "0.2.3"
25+
bson = "0.6.0"
26+
mongodb = "0.2.4"
2727
```
2828

2929
Alternately, you can use the MongoDB driver with SSL support. To do this, you must have OpenSSL installed on your system. Then, enable the `ssl` feature for MongoDB in your Cargo.toml:
3030

3131
```
3232
[dependencies]
3333
...
34-
mongodb = { version = "0.2.3", features = ["ssl"] }
34+
mongodb = { version = "0.2.4", features = ["ssl"] }
3535
```
3636

3737
Then, import the bson and driver libraries within your code.

tests/json/crud/arguments.rs

+21-21
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ impl Arguments {
5656
pub fn aggregate_from_json(object: &Map<String, Value>) -> Result<Arguments, String> {
5757
let options = AggregateOptions::from_json(object);
5858

59-
let array = val_or_err!(object.get("pipeline").map(Bson::from_json),
60-
Some(Bson::Array(arr)) => arr,
61-
"`aggregate` requires pipeline array");
59+
let array = val_or_err!(object.get("pipeline").map(Value::clone).map(Into::into),
60+
Some(Bson::Array(arr)) => arr,
61+
"`aggregate` requires pipeline array");
6262

6363
let mut docs = vec![];
6464
let mut out = false;
@@ -85,7 +85,7 @@ impl Arguments {
8585
pub fn count_from_json(object: &Map<String, Value>) -> Arguments {
8686
let options = CountOptions::from_json(object);
8787

88-
let filter = match object.get("filter").map(Bson::from_json) {
88+
let filter = match object.get("filter").map(Value::clone).map(Into::into) {
8989
Some(Bson::Document(doc)) => Some(doc),
9090
_ => None,
9191
};
@@ -97,7 +97,7 @@ impl Arguments {
9797
}
9898

9999
pub fn delete_from_json(object: &Map<String, Value>, many: bool) -> Result<Arguments, String> {
100-
let document = val_or_err!(object.get("filter").map(Bson::from_json),
100+
let document = val_or_err!(object.get("filter").map(Value::clone).map(Into::into),
101101
Some(Bson::Document(doc)) => doc,
102102
"`delete` requires document");
103103

@@ -108,11 +108,11 @@ impl Arguments {
108108
}
109109

110110
pub fn distinct_from_json(object: &Map<String, Value>) -> Result<Arguments, String> {
111-
let field_name = val_or_err!(object.get("fieldName").map(Bson::from_json),
111+
let field_name = val_or_err!(object.get("fieldName").map(Value::clone).map(Into::into),
112112
Some(Bson::String(ref s)) => s.to_owned(),
113113
"`distinct` requires field name");
114114

115-
let filter = match object.get("filter").map(Bson::from_json) {
115+
let filter = match object.get("filter").map(Value::clone).map(Into::into) {
116116
Some(Bson::Document(doc)) => Some(doc),
117117
_ => None,
118118
};
@@ -126,7 +126,7 @@ impl Arguments {
126126
pub fn find_from_json(object: &Map<String, Value>) -> Arguments {
127127
let options = FindOptions::from_json(object);
128128

129-
let filter = match object.get("filter").map(Bson::from_json) {
129+
let filter = match object.get("filter").map(Value::clone).map(Into::into) {
130130
Some(Bson::Document(doc)) => Some(doc),
131131
_ => None,
132132
};
@@ -140,7 +140,7 @@ impl Arguments {
140140
pub fn find_one_and_delete_from_json(object: &Map<String, Value>) -> Result<Arguments, String> {
141141
let options = FindOneAndDeleteOptions::from_json(object);
142142

143-
let filter = val_or_err!(object.get("filter").map(Bson::from_json),
143+
let filter = val_or_err!(object.get("filter").map(Value::clone).map(Into::into),
144144
Some(Bson::Document(doc)) => doc,
145145
"`find_one_and_delete` requires filter document");
146146

@@ -153,11 +153,11 @@ impl Arguments {
153153
pub fn find_one_and_replace_from_json(object: &Map<String, Value>) -> Result<Arguments, String> {
154154
let options = FindOneAndUpdateOptions::from_json(object);
155155

156-
let filter = val_or_err!(object.get("filter").map(Bson::from_json),
156+
let filter = val_or_err!(object.get("filter").map(Value::clone).map(Into::into),
157157
Some(Bson::Document(doc)) => doc,
158158
"`find_one_and_update` requires filter document");
159159

160-
let replacement = val_or_err!(object.get("replacement").map(Bson::from_json),
160+
let replacement = val_or_err!(object.get("replacement").map(Value::clone).map(Into::into),
161161
Some(Bson::Document(doc)) => doc,
162162
"`find_one_and_replace` requires replacement document");
163163

@@ -171,11 +171,11 @@ impl Arguments {
171171
pub fn find_one_and_update_from_json(object: &Map<String, Value>) -> Result<Arguments, String> {
172172
let options = FindOneAndUpdateOptions::from_json(object);
173173

174-
let filter = val_or_err!(object.get("filter").map(Bson::from_json),
174+
let filter = val_or_err!(object.get("filter").map(Value::clone).map(Into::into),
175175
Some(Bson::Document(doc)) => doc,
176176
"`find_one_and_update` requires filter document");
177177

178-
let update = val_or_err!(object.get("update").map(Bson::from_json),
178+
let update = val_or_err!(object.get("update").map(Value::clone).map(Into::into),
179179
Some(Bson::Document(doc)) => doc,
180180
"`find_one_and_update` requires update document");
181181

@@ -187,7 +187,7 @@ impl Arguments {
187187
}
188188

189189
pub fn insert_many_from_json(object: &Map<String, Value>) -> Result<Arguments, String> {
190-
let bsons = val_or_err!(object.get("documents").map(Bson::from_json),
190+
let bsons = val_or_err!(object.get("documents").map(Value::clone).map(Into::into),
191191
Some(Bson::Array(arr)) => arr,
192192
"`insert_many` requires documents");
193193

@@ -204,23 +204,23 @@ impl Arguments {
204204
}
205205

206206
pub fn insert_one_from_json(object: &Map<String, Value>) -> Result<Arguments, String> {
207-
let document = val_or_err!(object.get("document").map(Bson::from_json),
207+
let document = val_or_err!(object.get("document").map(Value::clone).map(Into::into),
208208
Some(Bson::Document(doc)) => doc,
209209
"`delete_one` requires document");
210210

211211
Ok(Arguments::InsertOne { document: document })
212212
}
213213

214214
pub fn replace_one_from_json(object: &Map<String, Value>) -> Result<Arguments, String> {
215-
let filter = val_or_err!(object.get("filter").map(Bson::from_json),
215+
let filter = val_or_err!(object.get("filter").map(Value::clone).map(Into::into),
216216
Some(Bson::Document(doc)) => doc,
217217
"`update` requires filter document");
218218

219-
let replacement = val_or_err!(object.get("replacement").map(Bson::from_json),
219+
let replacement = val_or_err!(object.get("replacement").map(Value::clone).map(Into::into),
220220
Some(Bson::Document(doc)) => doc,
221221
"`update` requires update document");
222222

223-
let upsert = var_match!(object.get("upsert").map(Bson::from_json),
223+
let upsert = var_match!(object.get("upsert").map(Value::clone).map(Into::into),
224224
Some(Bson::Boolean(b)) => b);
225225

226226
Ok(Arguments::ReplaceOne {
@@ -231,15 +231,15 @@ impl Arguments {
231231
}
232232

233233
pub fn update_from_json(object: &Map<String, Value>, many: bool) -> Result<Arguments, String> {
234-
let filter = val_or_err!(object.get("filter").map(Bson::from_json),
234+
let filter = val_or_err!(object.get("filter").map(Value::clone).map(Into::into),
235235
Some(Bson::Document(doc)) => doc,
236236
"`update` requires filter document");
237237

238-
let update = val_or_err!(object.get("update").map(Bson::from_json),
238+
let update = val_or_err!(object.get("update").map(Value::clone).map(Into::into),
239239
Some(Bson::Document(doc)) => doc,
240240
"`update` requires update document");
241241

242-
let upsert = var_match!(object.get("upsert").map(Bson::from_json),
242+
let upsert = var_match!(object.get("upsert").map(Value::clone).map(Into::into),
243243
Some(Bson::Boolean(b)) => b);
244244

245245
Ok(Arguments::Update {

tests/json/crud/options.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ impl FromValue for AggregateOptions {
1010
fn from_json(object: &Map<String, Value>) -> AggregateOptions {
1111
let mut options = AggregateOptions::new();
1212

13-
if let Some(Bson::I64(x)) = object.get("batchSize").map(Bson::from_json) {
13+
if let Some(Bson::I64(x)) = object.get("batchSize").map(Value::clone).map(Into::into) {
1414
options.batch_size = x as i32;
1515
};
1616

@@ -22,11 +22,11 @@ impl FromValue for CountOptions {
2222
fn from_json(object: &Map<String, Value>) -> CountOptions {
2323
let mut options = CountOptions::new();
2424

25-
if let Some(Bson::I64(x)) = object.get("skip").map(Bson::from_json) {
25+
if let Some(Bson::I64(x)) = object.get("skip").map(Value::clone).map(Into::into) {
2626
options.skip = Some(x);
2727
}
2828

29-
if let Some(Bson::I64(x)) = object.get("limit").map(Bson::from_json) {
29+
if let Some(Bson::I64(x)) = object.get("limit").map(Value::clone).map(Into::into) {
3030
options.limit = Some(x);
3131
}
3232

@@ -38,19 +38,19 @@ impl FromValue for FindOptions {
3838
fn from_json(object: &Map<String, Value>) -> FindOptions {
3939
let mut options = FindOptions::new();
4040

41-
if let Some(Bson::Document(doc)) = object.get("sort").map(Bson::from_json) {
41+
if let Some(Bson::Document(doc)) = object.get("sort").map(Value::clone).map(Into::into) {
4242
options.sort = Some(doc);
4343
}
4444

45-
if let Some(Bson::I64(x)) = object.get("skip").map(Bson::from_json) {
45+
if let Some(Bson::I64(x)) = object.get("skip").map(Value::clone).map(Into::into) {
4646
options.skip = Some(x);
4747
}
4848

49-
if let Some(Bson::I64(x)) = object.get("limit").map(Bson::from_json) {
49+
if let Some(Bson::I64(x)) = object.get("limit").map(Value::clone).map(Into::into) {
5050
options.limit = Some(x);
5151
}
5252

53-
if let Some(Bson::I64(x)) = object.get("batchSize").map(Bson::from_json) {
53+
if let Some(Bson::I64(x)) = object.get("batchSize").map(Value::clone).map(Into::into) {
5454
options.batch_size = Some(x as i32);
5555
}
5656

@@ -63,11 +63,11 @@ impl FromValue for FindOneAndDeleteOptions {
6363
fn from_json(object: &Map<String, Value>) -> FindOneAndDeleteOptions {
6464
let mut options = FindOneAndDeleteOptions::new();
6565

66-
if let Some(Bson::Document(projection)) = object.get("projection").map(Bson::from_json) {
66+
if let Some(Bson::Document(projection)) = object.get("projection").map(Value::clone).map(Into::into) {
6767
options.projection = Some(projection);
6868
}
6969

70-
if let Some(Bson::Document(sort)) = object.get("sort").map(Bson::from_json) {
70+
if let Some(Bson::Document(sort)) = object.get("sort").map(Value::clone).map(Into::into) {
7171
options.sort = Some(sort);
7272
}
7373

@@ -79,11 +79,11 @@ impl FromValue for FindOneAndUpdateOptions {
7979
fn from_json(object: &Map<String, Value>) -> FindOneAndUpdateOptions {
8080
let mut options = FindOneAndUpdateOptions::new();
8181

82-
if let Some(Bson::Document(projection)) = object.get("projection").map(Bson::from_json) {
82+
if let Some(Bson::Document(projection)) = object.get("projection").map(Value::clone).map(Into::into) {
8383
options.projection = Some(projection);
8484
}
8585

86-
if let Some(Bson::String(s)) = object.get("returnDocument").map(Bson::from_json) {
86+
if let Some(Bson::String(s)) = object.get("returnDocument").map(Value::clone).map(Into::into) {
8787
match s.as_ref() {
8888
"After" => options.return_document = Some(ReturnDocument::After),
8989
"Before" => options.return_document = Some(ReturnDocument::Before),
@@ -92,11 +92,11 @@ impl FromValue for FindOneAndUpdateOptions {
9292
}
9393

9494

95-
if let Some(Bson::Document(sort)) = object.get("sort").map(Bson::from_json) {
95+
if let Some(Bson::Document(sort)) = object.get("sort").map(Value::clone).map(Into::into) {
9696
options.sort = Some(sort);
9797
}
9898

99-
if let Some(Bson::Boolean(upsert)) = object.get("upsert").map(Bson::from_json) {
99+
if let Some(Bson::Boolean(upsert)) = object.get("upsert").map(Value::clone).map(Into::into) {
100100
options.upsert = Some(upsert);
101101
}
102102

tests/json/crud/outcome.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub struct Outcome {
1414
impl Outcome {
1515
pub fn from_json(object: &Map<String, Value>) -> Result<Outcome, String> {
1616
let result = match object.get("result") {
17-
Some(json) => Bson::from_json(json),
17+
Some(json) => Bson::from(json.clone()),
1818
None => Bson::Null,
1919
};
2020

@@ -40,7 +40,7 @@ impl Outcome {
4040
let mut data = vec![];
4141

4242
for json in array {
43-
match Bson::from_json(json) {
43+
match Bson::from(json.clone()) {
4444
Bson::Document(doc) => data.push(doc),
4545
_ => return Err(String::from("`data` array must contain only objects")),
4646
}

tests/json/crud/reader.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ fn get_data(object: &Map<String, Value>) -> Result<Vec<Document>, String> {
8080
let mut data = vec![];
8181

8282
for json in array {
83-
match Bson::from_json(&json) {
83+
match Bson::from(json) {
8484
Bson::Document(doc) => data.push(doc),
8585
_ => return Err(String::from("`data` array must contain only objects")),
8686
}

tests/json/sdam/responses.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl Responses {
2626

2727
let ismaster = val_or_err!(
2828
inner_array[1],
29-
Value::Object(ref obj) => Bson::from_json(&Value::Object(obj.clone())),
29+
Value::Object(ref obj) => Bson::from(Value::Object(obj.clone())),
3030
"Response item must contain the ismaster object as \
3131
the second argument.");
3232

0 commit comments

Comments
 (0)