Skip to content

Commit 5c3248b

Browse files
authored
RUST-680 Implement Copy for ObjectId (#237)
1 parent 0fc08b7 commit 5c3248b

File tree

7 files changed

+13
-13
lines changed

7 files changed

+13
-13
lines changed

src/bson.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ impl Bson {
729729
if let Ok(id) = db_pointer.get_object_id("$id") {
730730
return Bson::DbPointer(DbPointer {
731731
namespace: ns.into(),
732-
id: id.clone(),
732+
id,
733733
});
734734
}
735735
}
@@ -872,9 +872,9 @@ impl Bson {
872872
}
873873

874874
/// If `Bson` is `Objectid`, return its value. Returns `None` otherwise
875-
pub fn as_object_id(&self) -> Option<&oid::ObjectId> {
875+
pub fn as_object_id(&self) -> Option<oid::ObjectId> {
876876
match *self {
877-
Bson::ObjectId(ref v) => Some(v),
877+
Bson::ObjectId(v) => Some(v),
878878
_ => None,
879879
}
880880
}

src/document.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,10 @@ impl Document {
413413
}
414414
}
415415

416-
/// Get a reference to an object id value for this key if it exists and has the correct type.
417-
pub fn get_object_id(&self, key: &str) -> ValueAccessResult<&ObjectId> {
416+
/// Get an object id value for this key if it exists and has the correct type.
417+
pub fn get_object_id(&self, key: &str) -> ValueAccessResult<ObjectId> {
418418
match self.get(key) {
419-
Some(&Bson::ObjectId(ref v)) => Ok(v),
419+
Some(&Bson::ObjectId(v)) => Ok(v),
420420
Some(_) => Err(ValueAccessError::UnexpectedType),
421421
None => Err(ValueAccessError::NotPresent),
422422
}

src/oid.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl error::Error for Error {
6969
}
7070

7171
/// A wrapper around raw 12-byte ObjectId representations.
72-
#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
72+
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash)]
7373
pub struct ObjectId {
7474
id: [u8; 12],
7575
}

src/tests/modules/bson.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ fn from_impls() {
117117
Bson::from(b"abcdefghijkl"),
118118
Bson::ObjectId(ObjectId::with_bytes(*b"abcdefghijkl"))
119119
);
120-
assert_eq!(Bson::from(oid.clone()), Bson::ObjectId(oid.clone()));
120+
assert_eq!(Bson::from(oid), Bson::ObjectId(oid));
121121
assert_eq!(
122122
Bson::from(vec![1, 2, 3]),
123123
Bson::Array(vec![Bson::Int32(1), Bson::Int32(2), Bson::Int32(3)])

src/tests/modules/ordered.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ fn test_getters() {
146146
assert_eq!(Ok(&datetime), doc.get_datetime("datetime"));
147147

148148
let object_id = ObjectId::new();
149-
doc.insert("_id".to_string(), Bson::ObjectId(object_id.clone()));
150-
assert_eq!(Some(&Bson::ObjectId(object_id.clone())), doc.get("_id"));
151-
assert_eq!(Ok(&object_id), doc.get_object_id("_id"));
149+
doc.insert("_id".to_string(), Bson::ObjectId(object_id));
150+
assert_eq!(Some(&Bson::ObjectId(object_id)), doc.get("_id"));
151+
assert_eq!(Ok(object_id), doc.get_object_id("_id"));
152152

153153
assert_eq!(
154154
Some(&Bson::Binary(Binary {

src/tests/modules/ser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ fn int64() {
182182
fn oid() {
183183
let _guard = LOCK.run_concurrently();
184184
let oid = ObjectId::new();
185-
let obj = Bson::ObjectId(oid.clone());
185+
let obj = Bson::ObjectId(oid);
186186
let s: BTreeMap<String, String> = from_bson(obj.clone()).unwrap();
187187

188188
let mut expected = BTreeMap::new();

src/tests/serde.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ fn test_oid_helpers() {
738738
oid: oid.to_string(),
739739
};
740740
let doc = to_document(&a).unwrap();
741-
assert_eq!(doc.get_object_id("oid").unwrap(), &oid);
741+
assert_eq!(doc.get_object_id("oid").unwrap(), oid);
742742
}
743743

744744
#[test]

0 commit comments

Comments
 (0)