Skip to content

Commit 680cd5f

Browse files
committed
update tests to use ScopedBoxFuture
1 parent 102e9a2 commit 680cd5f

File tree

5 files changed

+25
-24
lines changed

5 files changed

+25
-24
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ use diesel::query_builder::{AsQuery, QueryFragment, QueryId};
7171
use diesel::row::Row;
7272
use diesel::{ConnectionResult, QueryResult};
7373
use futures::{Future, Stream};
74-
use scoped_futures::ScopedBoxFuture;
74+
75+
pub use scoped_futures::*;
7576

7677
#[cfg(feature = "mysql")]
7778
mod mysql;
@@ -180,7 +181,7 @@ where
180181
/// ```rust
181182
/// # include!("doctest_setup.rs");
182183
/// use diesel::result::Error;
183-
/// use futures::FutureExt;
184+
/// use scoped_futures::ScopedFutureExt;
184185
///
185186
/// # #[tokio::main(flavor = "current_thread")]
186187
/// # async fn main() {
@@ -200,7 +201,7 @@ where
200201
/// assert_eq!(vec!["Sean", "Tess", "Ruby"], all_names);
201202
///
202203
/// Ok(())
203-
/// }.boxed()).await?;
204+
/// }.scope_boxed()).await?;
204205
///
205206
/// conn.transaction::<(), _, _>(|conn| async move {
206207
/// diesel::insert_into(users)
@@ -214,7 +215,7 @@ where
214215
/// // If we want to roll back the transaction, but don't have an
215216
/// // actual error to return, we can return `RollbackTransaction`.
216217
/// Err(Error::RollbackTransaction)
217-
/// }.boxed()).await;
218+
/// }.scope_boxed()).await;
218219
///
219220
/// let all_names = users.select(name).load::<String>(conn).await?;
220221
/// assert_eq!(vec!["Sean", "Tess", "Ruby"], all_names);

src/pg/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ impl AsyncPgConnection {
271271
///
272272
/// ```rust
273273
/// # include!("../doctest_setup.rs");
274-
/// # use futures::FutureExt;
274+
/// # use scoped_futures::ScopedFutureExt;
275275
/// #
276276
/// # #[tokio::main(flavor = "current_thread")]
277277
/// # async fn main() {
@@ -285,7 +285,7 @@ impl AsyncPgConnection {
285285
/// .read_only()
286286
/// .serializable()
287287
/// .deferrable()
288-
/// .run(|conn| async move { Ok(()) }.boxed())
288+
/// .run(|conn| async move { Ok(()) }.scope_boxed())
289289
/// .await
290290
/// # }
291291
/// ```

src/pg/transaction_builder.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use diesel::backend::Backend;
33
use diesel::pg::Pg;
44
use diesel::query_builder::{AstPass, QueryBuilder, QueryFragment};
55
use diesel::QueryResult;
6-
use futures::future::BoxFuture;
6+
use scoped_futures::ScopedBoxFuture;
77

88
/// Used to build a transaction, specifying additional details.
99
///
@@ -77,7 +77,7 @@ where
7777
/// assert!(write_attempt.is_err());
7878
///
7979
/// Ok(())
80-
/// }) as _).await?;
80+
/// }).into()).await?;
8181
/// # sql_query("DROP TABLE users_for_read_only").execute(conn).await?;
8282
/// # Ok(())
8383
/// # }
@@ -127,7 +127,7 @@ where
127127
/// # /*
128128
/// Ok(())
129129
/// # */
130-
/// }) as _)
130+
/// }).into())
131131
/// .await
132132
/// # }
133133
/// ```
@@ -153,7 +153,7 @@ where
153153
/// # let conn = &mut connection_no_transaction().await;
154154
/// conn.build_transaction()
155155
/// .deferrable()
156-
/// .run(|conn| Box::pin(async { Ok(()) }))
156+
/// .run(|conn| Box::pin(async { Ok(()) }).into())
157157
/// .await
158158
/// # }
159159
/// ```
@@ -182,7 +182,7 @@ where
182182
/// # let conn = &mut connection_no_transaction().await;
183183
/// conn.build_transaction()
184184
/// .not_deferrable()
185-
/// .run(|conn| Box::pin(async { Ok(()) }) as _)
185+
/// .run(|conn| Box::pin(async { Ok(()) }).into())
186186
/// .await
187187
/// # }
188188
/// ```
@@ -211,7 +211,7 @@ where
211211
/// # let conn = &mut connection_no_transaction().await;
212212
/// conn.build_transaction()
213213
/// .read_committed()
214-
/// .run(|conn| Box::pin(async { Ok(()) }) as _)
214+
/// .run(|conn| Box::pin(async { Ok(()) }).into())
215215
/// .await
216216
/// # }
217217
/// ```
@@ -237,7 +237,7 @@ where
237237
/// # let conn = &mut connection_no_transaction().await;
238238
/// conn.build_transaction()
239239
/// .repeatable_read()
240-
/// .run(|conn| Box::pin(async { Ok(()) }) as _)
240+
/// .run(|conn| Box::pin(async { Ok(()) }).into())
241241
/// .await
242242
/// # }
243243
/// ```
@@ -263,7 +263,7 @@ where
263263
/// # let conn = &mut connection_no_transaction().await;
264264
/// conn.build_transaction()
265265
/// .serializable()
266-
/// .run(|conn| Box::pin(async { Ok(()) }) as _)
266+
/// .run(|conn| Box::pin(async { Ok(()) }).into())
267267
/// .await
268268
/// # }
269269
/// ```
@@ -283,10 +283,11 @@ where
283283
/// the original error will be returned, otherwise the error generated by the rollback
284284
/// will be returned. In the second case the connection should be considered broken
285285
/// as it contains a uncommitted unabortable open transaction.
286-
pub async fn run<T, E, F>(&mut self, f: F) -> Result<T, E>
286+
pub async fn run<'b, T, E, F>(&mut self, f: F) -> Result<T, E>
287287
where
288-
F: FnOnce(&mut C) -> BoxFuture<Result<T, E>> + Send,
289-
E: From<diesel::result::Error>,
288+
F: for<'r> FnOnce(&'r mut C) -> ScopedBoxFuture<'b, 'r, Result<T, E>> + Send + 'a,
289+
T: 'b,
290+
E: From<diesel::result::Error> + 'b,
290291
{
291292
let mut query_builder = <Pg as Backend>::QueryBuilder::default();
292293
self.to_sql(&mut query_builder, &Pg)?;

tests/lib.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use diesel::prelude::{ExpressionMethods, OptionalExtension, QueryDsl};
22
use diesel::QueryResult;
33
use diesel_async::*;
4-
use scoped_futures::ScopedFutureExt;
4+
use futures::FutureExt;
55
use std::fmt::Debug;
66

77
#[cfg(feature = "postgres")]
@@ -11,7 +11,7 @@ mod type_check;
1111
async fn transaction_test(conn: &mut TestConnection) -> QueryResult<()> {
1212
let res = conn
1313
.transaction::<i32, diesel::result::Error, _>(|conn| {
14-
async move {
14+
Box::pin(async move {
1515
let users: Vec<User> = users::table.load(conn).await?;
1616
assert_eq!(&users[0].name, "John Doe");
1717
assert_eq!(&users[1].name, "Jane Doe");
@@ -30,7 +30,7 @@ async fn transaction_test(conn: &mut TestConnection) -> QueryResult<()> {
3030
assert_eq!(count, 3);
3131
Ok(())
3232
}
33-
.scope_boxed()
33+
.boxed().into()
3434
})
3535
.await;
3636
assert!(res.is_ok());
@@ -47,8 +47,7 @@ async fn transaction_test(conn: &mut TestConnection) -> QueryResult<()> {
4747
assert_eq!(count, 4);
4848

4949
Err(diesel::result::Error::RollbackTransaction)
50-
}
51-
.scope_boxed()
50+
}).into()
5251
})
5352
.await;
5453
assert_eq!(

0 commit comments

Comments
 (0)