Skip to content

Commit 49bf9bf

Browse files
committed
Merge pull request #19 from thijsc/remove_to_owned
Remove some unnecessary to_owned calls
2 parents 56e2c47 + 998afa1 commit 49bf9bf

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

src/ordered.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl<'a> Iterator for OrderedDocumentIntoIterator {
102102
match self.vec_iter.next() {
103103
Some(key) => {
104104
let val = self.document.remove(&key[..]).unwrap();
105-
Some((key, val.to_owned()))
105+
Some((key, val))
106106
},
107107
None => None,
108108
}
@@ -202,7 +202,7 @@ impl OrderedDocument {
202202
}
203203

204204
self.keys.push(key.to_owned());
205-
self.document.insert(key, val.to_owned())
205+
self.document.insert(key, val)
206206
}
207207

208208
/// Takes the value of the entry out of the document, and returns it.

tests/modules/bson.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ use bson::{Bson, Document};
33
#[test]
44
fn to_json() {
55
let mut doc = Document::new();
6-
doc.insert("first".to_owned(), Bson::I32(1));
7-
doc.insert("second".to_owned(), Bson::String("foo".to_owned()));
8-
doc.insert("alphanumeric".to_owned(), Bson::String("bar".to_owned()));
6+
doc.insert("first", Bson::I32(1));
7+
doc.insert("second", Bson::String("foo".to_owned()));
8+
doc.insert("alphanumeric", Bson::String("bar".to_owned()));
99
let data = Bson::Document(doc).to_json();
1010

1111
assert!(data.is_object());

tests/modules/encoder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn test_encode_utf8_string() {
2525
let dst = [28, 0, 0, 0, 2, 107, 101, 121, 0, 14, 0, 0, 0, 116, 101, 115, 116, 228, 189, 160, 229, 165, 189, 229, 144, 151, 0, 0];
2626

2727
let mut doc = Document::new();
28-
doc.insert("key".to_owned(), Bson::String(src));
28+
doc.insert("key", Bson::String(src));
2929

3030
let mut buf = Vec::new();
3131
encode_document(&mut buf, &doc).unwrap();
@@ -39,7 +39,7 @@ fn test_encode_array() {
3939
let dst = [37, 0, 0, 0, 4, 107, 101, 121, 0, 27, 0, 0, 0, 1, 48, 0, 41, 92, 143, 194, 245, 40, 240, 63, 2, 49, 0, 4, 0, 0, 0, 120, 121, 122, 0, 0, 0];
4040

4141
let mut doc = Document::new();
42-
doc.insert("key".to_owned(), Bson::Array(src));
42+
doc.insert("key", Bson::Array(src));
4343

4444
let mut buf = Vec::new();
4545
encode_document(&mut buf, &doc).unwrap();
@@ -53,7 +53,7 @@ fn test_encode_utc_date_time() {
5353
let dst = [18, 0, 0, 0, 9, 107, 101, 121, 0, 208, 111, 158, 149, 43, 1, 0, 0, 0];
5454

5555
let mut doc = Document::new();
56-
doc.insert("key".to_owned(), Bson::UtcDatetime(src));
56+
doc.insert("key", Bson::UtcDatetime(src));
5757

5858
let mut buf = Vec::new();
5959
encode_document(&mut buf, &doc).unwrap();

tests/modules/ordered.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ fn ordered_insert_shorthand() {
3737
#[test]
3838
fn remove() {
3939
let mut doc = Document::new();
40-
doc.insert("first".to_owned(), Bson::I32(1));
41-
doc.insert("second".to_owned(), Bson::String("foo".to_owned()));
42-
doc.insert("alphanumeric".to_owned(), Bson::String("bar".to_owned()));
40+
doc.insert("first", Bson::I32(1));
41+
doc.insert("second", Bson::String("foo".to_owned()));
42+
doc.insert("alphanumeric", Bson::String("bar".to_owned()));
4343

4444
assert!(doc.remove("second").is_some());
4545
assert!(doc.remove("none").is_none());

0 commit comments

Comments
 (0)