Repository: mongodb/mongo-rust-driver (language: rust)

Issue:
Use Arc::clone in Collection::clone_with_type
Current `clone_with_type` implementation includes calling builder and constructing a new `CollectionInner` instance.
Given that `CollectionInner` is wrapped in an Arc, and generic T isn't included in `CollectionInner`, is there any possibility that we refactor `clone_with_type` into `Self{inner: self.inner.clone(), _phantom: Default::default()}`?


Discussion / hints:
Hi @PhontonQuantum, thanks for bringing this up! We think that would be a nice improvement and would be happy to merge such a change if you'd like to submit a PR for it.

Fix patch:
diff --git a/src/coll/mod.rs b/src/coll/mod.rs
index 89768e567..eedbeee21 100644
--- a/src/coll/mod.rs
+++ b/src/coll/mod.rs
@@ -167,13 +167,10 @@ impl<T> Collection<T> {
 
     /// Gets a clone of the `Collection` with a different type `U`.
     pub fn clone_with_type<U>(&self) -> Collection<U> {
-        let options = CollectionOptions::builder()
-            .selection_criteria(self.inner.selection_criteria.clone())
-            .read_concern(self.inner.read_concern.clone())
-            .write_concern(self.inner.write_concern.clone())
-            .build();
-
-        Collection::new(self.inner.db.clone(), &self.inner.name, Some(options))
+        Collection {
+            inner: self.inner.clone(),
+            _phantom: Default::default(),
+        }
     }
 
     /// Get the `Client` that this collection descended from.


Test patch: