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

Commit f8345ed

Browse files
committed
removed unnecessary "to_owned" calls
1 parent 3d72ca2 commit f8345ed

File tree

8 files changed

+94
-94
lines changed

8 files changed

+94
-94
lines changed

src/coll/mod.rs

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ impl Collection {
9393

9494
let mut spec = bson::Document::new();
9595
let mut cursor = bson::Document::new();
96-
cursor.insert("batchSize".to_owned(), Bson::I32(opts.batch_size));
97-
spec.insert("aggregate".to_owned(), Bson::String(self.name()));
98-
spec.insert("pipeline".to_owned(), Bson::Array(pipeline_map));
99-
spec.insert("cursor".to_owned(), Bson::Document(cursor));
96+
cursor.insert("batchSize", Bson::I32(opts.batch_size));
97+
spec.insert("aggregate", Bson::String(self.name()));
98+
spec.insert("pipeline", Bson::Array(pipeline_map));
99+
spec.insert("cursor", Bson::Document(cursor));
100100
if opts.allow_disk_use {
101-
spec.insert("allowDiskUse".to_owned(), Bson::Boolean(opts.allow_disk_use));
101+
spec.insert("allowDiskUse", Bson::Boolean(opts.allow_disk_use));
102102
}
103103

104104
let read_pref = opts.read_preference.unwrap_or(self.read_preference.to_owned());
@@ -111,18 +111,18 @@ impl Collection {
111111
let opts = options.unwrap_or(CountOptions::new());
112112

113113
let mut spec = bson::Document::new();
114-
spec.insert("count".to_owned(), Bson::String(self.name()));
115-
spec.insert("skip".to_owned(), Bson::I64(opts.skip as i64));
116-
spec.insert("limit".to_owned(), Bson::I64(opts.limit));
114+
spec.insert("count", Bson::String(self.name()));
115+
spec.insert("skip", Bson::I64(opts.skip as i64));
116+
spec.insert("limit", Bson::I64(opts.limit));
117117
if filter.is_some() {
118-
spec.insert("query".to_owned(), Bson::Document(filter.unwrap()));
118+
spec.insert("query", Bson::Document(filter.unwrap()));
119119
}
120120

121121
// Favor specified hint document over string
122122
if opts.hint_doc.is_some() {
123-
spec.insert("hint".to_owned(), Bson::Document(opts.hint_doc.unwrap()));
123+
spec.insert("hint", Bson::Document(opts.hint_doc.unwrap()));
124124
} else if opts.hint.is_some() {
125-
spec.insert("hint".to_owned(), Bson::String(opts.hint.unwrap()));
125+
spec.insert("hint", Bson::String(opts.hint.unwrap()));
126126
}
127127

128128
let read_pref = opts.read_preference.unwrap_or(self.read_preference.to_owned());
@@ -141,10 +141,10 @@ impl Collection {
141141
let opts = options.unwrap_or(DistinctOptions::new());
142142

143143
let mut spec = bson::Document::new();
144-
spec.insert("distinct".to_owned(), Bson::String(self.name()));
145-
spec.insert("key".to_owned(), Bson::String(field_name.to_owned()));
144+
spec.insert("distinct", Bson::String(self.name()));
145+
spec.insert("key", Bson::String(field_name.to_owned()));
146146
if filter.is_some() {
147-
spec.insert("query".to_owned(), Bson::Document(filter.unwrap()));
147+
spec.insert("query", Bson::Document(filter.unwrap()));
148148
}
149149

150150
let read_pref = opts.read_preference.unwrap_or(self.read_preference.to_owned());
@@ -217,14 +217,14 @@ impl Collection {
217217
let wc = write_concern.unwrap_or(self.write_concern.clone());
218218

219219
let mut new_cmd = bson::Document::new();
220-
new_cmd.insert("findAndModify".to_owned(), Bson::String(self.name()));
221-
new_cmd.insert("query".to_owned(), Bson::Document(filter));
222-
new_cmd.insert("writeConcern".to_owned(), Bson::Document(wc.to_bson()));
220+
new_cmd.insert("findAndModify", Bson::String(self.name()));
221+
new_cmd.insert("query", Bson::Document(filter));
222+
new_cmd.insert("writeConcern", Bson::Document(wc.to_bson()));
223223
if sort.is_some() {
224-
new_cmd.insert("sort".to_owned(), Bson::Document(sort.unwrap()));
224+
new_cmd.insert("sort", Bson::Document(sort.unwrap()));
225225
}
226226
if projection.is_some() {
227-
new_cmd.insert("fields".to_owned(), Bson::Document(projection.unwrap()));
227+
new_cmd.insert("fields", Bson::Document(projection.unwrap()));
228228
}
229229

230230
for (key, val) in cmd.iter() {
@@ -249,12 +249,12 @@ impl Collection {
249249
Option<WriteConcern>, cmd_type: CommandType) -> Result<Option<bson::Document>> {
250250

251251
let mut cmd = bson::Document::new();
252-
cmd.insert("update".to_owned(), Bson::Document(update));
252+
cmd.insert("update", Bson::Document(update));
253253
if after {
254-
cmd.insert("new".to_owned(), Bson::Boolean(true));
254+
cmd.insert("new", Bson::Boolean(true));
255255
}
256256
if upsert {
257-
cmd.insert("upsert".to_owned(), Bson::Boolean(true));
257+
cmd.insert("upsert", Bson::Boolean(true));
258258
}
259259

260260
self.find_and_modify(&mut cmd, filter, max_time_ms, projection, sort, write_concern,
@@ -267,7 +267,7 @@ impl Collection {
267267

268268
let opts = options.unwrap_or(FindOneAndDeleteOptions::new());
269269
let mut cmd = bson::Document::new();
270-
cmd.insert("remove".to_owned(), Bson::Boolean(true));
270+
cmd.insert("remove", Bson::Boolean(true));
271271
self.find_and_modify(&mut cmd, filter, opts.max_time_ms,
272272
opts.projection, opts.sort, opts.write_concern,
273273
CommandType::FindOneAndDelete)
@@ -483,18 +483,18 @@ impl Collection {
483483
Some(id) => ids.push(id.clone()),
484484
None => {
485485
let id = Bson::ObjectId(try!(oid::ObjectId::new()));
486-
cdoc.insert("_id".to_owned(), id.clone());
486+
cdoc.insert("_id", id.clone());
487487
ids.push(id);
488488
}
489489
}
490490
converted_docs.push(Bson::Document(cdoc));
491491
}
492492

493493
let mut cmd = bson::Document::new();
494-
cmd.insert("insert".to_owned(), Bson::String(self.name()));
495-
cmd.insert("documents".to_owned(), Bson::Array(converted_docs));
496-
cmd.insert("ordered".to_owned(), Bson::Boolean(ordered));
497-
cmd.insert("writeConcern".to_owned(), Bson::Document(wc.to_bson()));
494+
cmd.insert("insert", Bson::String(self.name()));
495+
cmd.insert("documents", Bson::Array(converted_docs));
496+
cmd.insert("ordered", Bson::Boolean(ordered));
497+
cmd.insert("writeConcern", Bson::Document(wc.to_bson()));
498498

499499
let result = try!(self.db.command(cmd, cmd_type, None));
500500

@@ -568,19 +568,19 @@ impl Collection {
568568
let mut deletes = Vec::new();
569569
for model in models {
570570
let mut delete = bson::Document::new();
571-
delete.insert("q".to_owned(), Bson::Document(model.filter));
571+
delete.insert("q", Bson::Document(model.filter));
572572
let limit = if model.multi { 0 } else { 1 };
573-
delete.insert("limit".to_owned(), Bson::I64(limit));
573+
delete.insert("limit", Bson::I64(limit));
574574
deletes.push(Bson::Document(delete));
575575
}
576576

577577
let mut cmd = bson::Document::new();
578-
cmd.insert("delete".to_owned(), Bson::String(self.name()));
579-
cmd.insert("deletes".to_owned(), Bson::Array(deletes));
578+
cmd.insert("delete", Bson::String(self.name()));
579+
cmd.insert("deletes", Bson::Array(deletes));
580580
if !ordered {
581-
cmd.insert("ordered".to_owned(), Bson::Boolean(ordered));
581+
cmd.insert("ordered", Bson::Boolean(ordered));
582582
}
583-
cmd.insert("writeConcern".to_owned(), Bson::Document(wc.to_bson()));
583+
cmd.insert("writeConcern", Bson::Document(wc.to_bson()));
584584

585585
let result = try!(self.db.command(cmd, cmd_type, None));
586586

@@ -631,22 +631,22 @@ impl Collection {
631631
let mut updates = Vec::new();
632632
for model in models {
633633
let mut update = bson::Document::new();
634-
update.insert("q".to_owned(), Bson::Document(model.filter));
635-
update.insert("u".to_owned(), Bson::Document(model.update));
636-
update.insert("upsert".to_owned(), Bson::Boolean(model.upsert));
634+
update.insert("q", Bson::Document(model.filter));
635+
update.insert("u", Bson::Document(model.update));
636+
update.insert("upsert", Bson::Boolean(model.upsert));
637637
if !ordered {
638-
update.insert("ordered".to_owned(), Bson::Boolean(ordered));
638+
update.insert("ordered", Bson::Boolean(ordered));
639639
}
640640
if model.multi {
641-
update.insert("multi".to_owned(), Bson::Boolean(model.multi));
641+
update.insert("multi", Bson::Boolean(model.multi));
642642
}
643643
updates.push(Bson::Document(update));
644644
}
645645

646646
let mut cmd = bson::Document::new();
647-
cmd.insert("update".to_owned(), Bson::String(self.name()));
648-
cmd.insert("updates".to_owned(), Bson::Array(updates));
649-
cmd.insert("writeConcern".to_owned(), Bson::Document(wc.to_bson()));
647+
cmd.insert("update", Bson::String(self.name()));
648+
cmd.insert("updates", Bson::Array(updates));
649+
cmd.insert("writeConcern", Bson::Document(wc.to_bson()));
650650

651651
let result = try!(self.db.command(cmd, cmd_type, None));
652652

@@ -741,8 +741,8 @@ impl Collection {
741741
}
742742

743743
let mut cmd = bson::Document::new();
744-
cmd.insert("createIndexes".to_owned(), Bson::String(self.name()));
745-
cmd.insert("indexes".to_owned(), Bson::Array(indexes));
744+
cmd.insert("createIndexes", Bson::String(self.name()));
745+
cmd.insert("indexes", Bson::Array(indexes));
746746
let result = try!(self.db.command(cmd, CommandType::CreateIndexes, None));
747747

748748
match result.get("errmsg") {
@@ -769,8 +769,8 @@ impl Collection {
769769
/// Drop an index by IndexModel.
770770
pub fn drop_index_model(&self, model: IndexModel) -> Result<()> {
771771
let mut cmd = bson::Document::new();
772-
cmd.insert("dropIndexes".to_owned(), Bson::String(self.name()));
773-
cmd.insert("index".to_owned(), Bson::String(try!(model.name())));
772+
cmd.insert("dropIndexes", Bson::String(self.name()));
773+
cmd.insert("index", Bson::String(try!(model.name())));
774774

775775
let result = try!(self.db.command(cmd, CommandType::DropIndexes, None));
776776
match result.get("errmsg") {
@@ -791,7 +791,7 @@ impl Collection {
791791
/// List all indexes in the collection.
792792
pub fn list_indexes(&self) -> Result<Cursor> {
793793
let mut cmd = bson::Document::new();
794-
cmd.insert("listIndexes".to_owned(), Bson::String(self.name()));
794+
cmd.insert("listIndexes", Bson::String(self.name()));
795795
self.db.command_cursor(cmd, CommandType::ListIndexes, self.read_preference.to_owned())
796796
}
797797
}

src/coll/options.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -311,57 +311,57 @@ impl IndexModel {
311311
/// Converts the model to its BSON document representation.
312312
pub fn to_bson(&self) -> Result<bson::Document> {
313313
let mut doc = bson::Document::new();
314-
doc.insert("key".to_owned(), Bson::Document(self.keys.clone()));
314+
doc.insert("key", Bson::Document(self.keys.clone()));
315315

316316
if let Some(ref val) = self.options.background {
317-
doc.insert("background".to_owned(), Bson::Boolean(*val));
317+
doc.insert("background", Bson::Boolean(*val));
318318
}
319319
if let Some(ref val) = self.options.expire_after_seconds {
320-
doc.insert("expireAfterSeconds".to_owned(), Bson::I32(*val));
320+
doc.insert("expireAfterSeconds", Bson::I32(*val));
321321
}
322322
if let Some(ref val) = self.options.name {
323-
doc.insert("name".to_owned(), Bson::String(val.to_owned()));
323+
doc.insert("name", Bson::String(val.to_owned()));
324324
} else {
325-
doc.insert("name".to_owned(), Bson::String(try!(self.generate_index_name())));
325+
doc.insert("name", Bson::String(try!(self.generate_index_name())));
326326
}
327327
if let Some(ref val) = self.options.sparse {
328-
doc.insert("sparse".to_owned(), Bson::Boolean(*val));
328+
doc.insert("sparse", Bson::Boolean(*val));
329329
}
330330
if let Some(ref val) = self.options.storage_engine {
331-
doc.insert("storageEngine".to_owned(), Bson::String(val.to_owned()));
331+
doc.insert("storageEngine", Bson::String(val.to_owned()));
332332
}
333333
if let Some(ref val) = self.options.unique {
334-
doc.insert("unique".to_owned(), Bson::Boolean(*val));
334+
doc.insert("unique", Bson::Boolean(*val));
335335
}
336336
if let Some(ref val) = self.options.version {
337-
doc.insert("v".to_owned(), Bson::I32(*val));
337+
doc.insert("v", Bson::I32(*val));
338338
}
339339
if let Some(ref val) = self.options.default_language {
340-
doc.insert("default_language".to_owned(), Bson::String(val.to_owned()));
340+
doc.insert("default_language", Bson::String(val.to_owned()));
341341
}
342342
if let Some(ref val) = self.options.language_override {
343-
doc.insert("language_override".to_owned(), Bson::String(val.to_owned()));
343+
doc.insert("language_override", Bson::String(val.to_owned()));
344344
}
345345
if let Some(ref val) = self.options.text_version {
346-
doc.insert("textIndexVersion".to_owned(), Bson::I32(*val));
346+
doc.insert("textIndexVersion", Bson::I32(*val));
347347
}
348348
if let Some(ref val) = self.options.weights {
349-
doc.insert("weights".to_owned(), Bson::Document(val.clone()));
349+
doc.insert("weights", Bson::Document(val.clone()));
350350
}
351351
if let Some(ref val) = self.options.sphere_version {
352-
doc.insert("2dsphereIndexVersion".to_owned(), Bson::I32(*val));
352+
doc.insert("2dsphereIndexVersion", Bson::I32(*val));
353353
}
354354
if let Some(ref val) = self.options.bits {
355-
doc.insert("bits".to_owned(), Bson::I32(*val));
355+
doc.insert("bits", Bson::I32(*val));
356356
}
357357
if let Some(ref val) = self.options.max {
358-
doc.insert("max".to_owned(), Bson::FloatingPoint(*val));
358+
doc.insert("max", Bson::FloatingPoint(*val));
359359
}
360360
if let Some(ref val) = self.options.min {
361-
doc.insert("min".to_owned(), Bson::FloatingPoint(*val));
361+
doc.insert("min", Bson::FloatingPoint(*val));
362362
}
363363
if let Some(ref val) = self.options.bucket_size {
364-
doc.insert("bucketSize".to_owned(), Bson::I32(*val));
364+
doc.insert("bucketSize", Bson::I32(*val));
365365
}
366366

367367
Ok(doc)

src/common.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ impl ReadPreference {
5252
let bson_tag_sets: Vec<_> = self.tag_sets.iter().map(|map| {
5353
let mut bson_map = bson::Document::new();
5454
for (key, val) in map.iter() {
55-
bson_map.insert(key.to_owned(), Bson::String(val.to_owned()));
55+
bson_map.insert(&key[..], Bson::String(val.to_owned()));
5656
}
5757
Bson::Document(bson_map)
5858
}).collect();
5959

60-
doc.insert("tag_sets".to_owned(), Bson::Array(bson_tag_sets));
60+
doc.insert("tag_sets", Bson::Array(bson_tag_sets));
6161
doc
6262
}
6363
}
@@ -86,9 +86,9 @@ impl WriteConcern {
8686

8787
pub fn to_bson(&self) -> bson::Document {
8888
let mut bson = bson::Document::new();
89-
bson.insert("w".to_owned(), Bson::I32(self.w));
90-
bson.insert("wtimeout".to_owned(), Bson::I32(self.w_timeout));
91-
bson.insert("j".to_owned(), Bson::Boolean(self.j));
89+
bson.insert("w", Bson::I32(self.w));
90+
bson.insert("wtimeout", Bson::I32(self.w_timeout));
91+
bson.insert("j", Bson::Boolean(self.j));
9292
bson
9393
}
9494
}

src/cursor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,13 @@ impl Cursor {
223223
Some(_) => {
224224
// Query is already formatted as a $query document; add onto it.
225225
let mut nq = query.clone();
226-
nq.insert("read_preference".to_owned(), Bson::Document(read_pref.to_document()));
226+
nq.insert("read_preference", Bson::Document(read_pref.to_document()));
227227
nq
228228
},
229229
None => {
230230
// Convert the query to a $query document.
231231
let mut nq = doc! { "$query" => query };
232-
nq.insert("read_preference".to_owned(), Bson::Document(read_pref.to_document()));
232+
nq.insert("read_preference", Bson::Document(read_pref.to_document()));
233233
nq
234234
}
235235
}

0 commit comments

Comments
 (0)