Skip to content

Commit

Permalink
RUST-993 Implement Clone for Collection<T> (mongodb#454)
Browse files Browse the repository at this point in the history
Because derive is too conservative, derive only implements Clone for Collection<T> if T is Clone.
Collection<T> does not actually store any value of type T (so T does not need to be Clone).
  • Loading branch information
awitten1 authored and Andrew Witten committed Sep 9, 2021
1 parent f39ce8b commit 7acc9b1
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/coll/mod.rs
Expand Up @@ -111,12 +111,23 @@ use crate::{
/// # }
/// ```

#[derive(Debug, Clone)]
#[derive(Debug)]
pub struct Collection<T> {
inner: Arc<CollectionInner>,
_phantom: std::marker::PhantomData<T>,
}

// Because derive is too conservative, derive only implements Clone if T is Clone.
// Collection<T> does not actually store any value of type T (so T does not need to be clone).
impl<T> Clone for Collection<T> {
fn clone(&self) -> Self {
Self {
inner: self.inner.clone(),
_phantom: Default::default(),
}
}
}

#[derive(Debug)]
struct CollectionInner {
client: Client,
Expand Down

0 comments on commit 7acc9b1

Please sign in to comment.