Skip to content

Commit 5fdda29

Browse files
RUST-1876 Require T: Send + Sync for Collection<T> (#1043)
1 parent c00348f commit 5fdda29

File tree

20 files changed

+139
-50
lines changed

20 files changed

+139
-50
lines changed

src/action.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ pub(crate) struct CollRef<'a> {
202202
}
203203

204204
impl<'a> CollRef<'a> {
205-
fn new<T>(coll: &'a Collection<T>) -> Self {
205+
fn new<T: Send + Sync>(coll: &'a Collection<T>) -> Self {
206206
Self {
207207
inner: coll.clone_with_type(),
208208
_ref: PhantomData,

src/action/aggregate.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ impl Database {
3636
}
3737
}
3838

39-
impl<T> Collection<T> {
39+
impl<T> Collection<T>
40+
where
41+
T: Send + Sync,
42+
{
4043
/// Runs an aggregation operation.
4144
///
4245
/// See the documentation [here](https://www.mongodb.com/docs/manual/aggregation/) for more
@@ -69,7 +72,10 @@ impl crate::sync::Database {
6972
}
7073

7174
#[cfg(feature = "sync")]
72-
impl<T> crate::sync::Collection<T> {
75+
impl<T> crate::sync::Collection<T>
76+
where
77+
T: Send + Sync,
78+
{
7379
/// Runs an aggregation operation.
7480
///
7581
/// See the documentation [here](https://www.mongodb.com/docs/manual/aggregation/) for more

src/action/count.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ use crate::{
99

1010
use super::{action_impl, option_setters, CollRef};
1111

12-
impl<T> Collection<T> {
12+
impl<T> Collection<T>
13+
where
14+
T: Send + Sync,
15+
{
1316
/// Estimates the number of documents in the collection using collection metadata.
1417
///
1518
/// Due to an oversight in versions 5.0.0 - 5.0.7 of MongoDB, the `count` server command,
@@ -46,7 +49,10 @@ impl<T> Collection<T> {
4649
}
4750

4851
#[cfg(feature = "sync")]
49-
impl<T> crate::sync::Collection<T> {
52+
impl<T> crate::sync::Collection<T>
53+
where
54+
T: Send + Sync,
55+
{
5056
/// Estimates the number of documents in the collection using collection metadata.
5157
///
5258
/// Due to an oversight in versions 5.0.0 - 5.0.7 of MongoDB, the `count` server command,

src/action/create_index.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ use crate::{
1515

1616
use super::{action_impl, option_setters, CollRef, Multiple, Single};
1717

18-
impl<T> Collection<T> {
18+
impl<T> Collection<T>
19+
where
20+
T: Send + Sync,
21+
{
1922
/// Creates the given index on this collection.
2023
///
2124
/// `await` will return `Result<CreateIndexResult>`.
@@ -46,8 +49,11 @@ impl<T> Collection<T> {
4649
}
4750
}
4851

49-
#[cfg(any(feature = "sync", feature = "tokio-sync"))]
50-
impl<T> crate::sync::Collection<T> {
52+
#[cfg(feature = "sync")]
53+
impl<T> crate::sync::Collection<T>
54+
where
55+
T: Send + Sync,
56+
{
5157
/// Creates the given index on this collection.
5258
///
5359
/// [`run`](CreateIndex::run) will return `Result<CreateIndexResult>`.

src/action/delete.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ use crate::{
1313

1414
use super::{action_impl, option_setters, CollRef};
1515

16-
impl<T> Collection<T> {
16+
impl<T> Collection<T>
17+
where
18+
T: Send + Sync,
19+
{
1720
/// Deletes up to one document found matching `query`.
1821
///
1922
/// This operation will retry once upon failure if the connection and encountered error support
@@ -46,8 +49,11 @@ impl<T> Collection<T> {
4649
}
4750
}
4851

49-
#[cfg(any(feature = "sync", feature = "tokio-sync"))]
50-
impl<T> crate::sync::Collection<T> {
52+
#[cfg(feature = "sync")]
53+
impl<T> crate::sync::Collection<T>
54+
where
55+
T: Send + Sync,
56+
{
5157
/// Deletes up to one document found matching `query`.
5258
///
5359
/// This operation will retry once upon failure if the connection and encountered error support

src/action/distinct.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ use crate::{
1515

1616
use super::{action_impl, option_setters, CollRef};
1717

18-
impl<T> Collection<T> {
18+
impl<T> Collection<T>
19+
where
20+
T: Send + Sync,
21+
{
1922
/// Finds the distinct values of the field specified by `field_name` across the collection.
2023
///
2124
/// `await` will return `Result<Vec<Bson>>`.
@@ -30,8 +33,11 @@ impl<T> Collection<T> {
3033
}
3134
}
3235

33-
#[cfg(any(feature = "sync", feature = "tokio-sync"))]
34-
impl<T> crate::sync::Collection<T> {
36+
#[cfg(feature = "sync")]
37+
impl<T> crate::sync::Collection<T>
38+
where
39+
T: Send + Sync,
40+
{
3541
/// Finds the distinct values of the field specified by `field_name` across the collection.
3642
///
3743
/// [`run`](Distinct::run) will return `Result<Vec<Bson>>`.

src/action/drop.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ action_impl! {
6969
}
7070
}
7171

72-
impl<T> Collection<T> {
72+
impl<T> Collection<T>
73+
where
74+
T: Send + Sync,
75+
{
7376
/// Drops the collection, deleting all data and indexes stored in it.
7477
///
7578
/// `await` will return `Result<()>`.
@@ -83,7 +86,10 @@ impl<T> Collection<T> {
8386
}
8487

8588
#[cfg(feature = "sync")]
86-
impl<T> crate::sync::Collection<T> {
89+
impl<T> crate::sync::Collection<T>
90+
where
91+
T: Send + Sync,
92+
{
8793
/// Drops the collection, deleting all data and indexes stored in it.
8894
///
8995
/// [`run`](DropCollection::run) will return `Result<()>`.

src/action/drop_index.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ use crate::{
1212
Collection,
1313
};
1414

15-
impl<T> Collection<T> {
15+
impl<T> Collection<T>
16+
where
17+
T: Send + Sync,
18+
{
1619
/// Drops the index specified by `name` from this collection.
1720
///
1821
/// `await` will return `Result<()>`.
@@ -38,8 +41,11 @@ impl<T> Collection<T> {
3841
}
3942
}
4043

41-
#[cfg(any(feature = "sync", feature = "tokio-sync"))]
42-
impl<T> crate::sync::Collection<T> {
44+
#[cfg(feature = "sync")]
45+
impl<T> crate::sync::Collection<T>
46+
where
47+
T: Send + Sync,
48+
{
4349
/// Drops the index specified by `name` from this collection.
4450
///
4551
/// [`run`](DropIndex::run) will return `Result<()>`.

src/action/list_indexes.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ use super::{
2424
ListSpecifications,
2525
};
2626

27-
impl<T> Collection<T> {
27+
impl<T> Collection<T>
28+
where
29+
T: Send + Sync,
30+
{
2831
/// Lists all indexes on this collection.
2932
///
3033
/// `await` will return `Result<Cursor<IndexModel>>` (or `Result<SessionCursor<IndexModel>>` if
@@ -51,8 +54,11 @@ impl<T> Collection<T> {
5154
}
5255
}
5356

54-
#[cfg(any(feature = "sync", feature = "tokio-sync"))]
55-
impl<T> crate::sync::Collection<T> {
57+
#[cfg(feature = "sync")]
58+
impl<T> crate::sync::Collection<T>
59+
where
60+
T: Send + Sync,
61+
{
5662
/// Lists all indexes on this collection.
5763
///
5864
/// [`run`](ListIndexes::run) will return `Result<Cursor<IndexModel>>` (or

src/action/update.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ use crate::{
1313

1414
use super::{action_impl, option_setters, CollRef};
1515

16-
impl<T> Collection<T> {
16+
impl<T> Collection<T>
17+
where
18+
T: Send + Sync,
19+
{
1720
/// Updates all documents matching `query` in the collection.
1821
///
1922
/// Both `Document` and `Vec<Document>` implement `Into<UpdateModifications>`, so either can be
@@ -58,8 +61,11 @@ impl<T> Collection<T> {
5861
}
5962
}
6063

61-
#[cfg(any(feature = "sync", feature = "tokio-sync"))]
62-
impl<T> crate::sync::Collection<T> {
64+
#[cfg(feature = "sync")]
65+
impl<T> crate::sync::Collection<T>
66+
where
67+
T: Send + Sync,
68+
{
6369
/// Updates all documents matching `query` in the collection.
6470
///
6571
/// Both `Document` and `Vec<Document>` implement `Into<UpdateModifications>`, so either can be

0 commit comments

Comments
 (0)