Skip to content

Commit 0fe9352

Browse files
authored
Merge pull request #238 from paolobarbolini/reduce-futures-util
2 parents bf66d1d + dd64b6e commit 0fe9352

File tree

9 files changed

+45
-35
lines changed

9 files changed

+45
-35
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ description = "An async extension for Diesel the safe, extensible ORM and Query
1313
rust-version = "1.82.0"
1414

1515
[dependencies]
16+
futures-core = "0.3.17"
1617
futures-channel = { version = "0.3.17", default-features = false, features = [
1718
"std",
1819
"sink",
1920
], optional = true }
2021
futures-util = { version = "0.3.17", default-features = false, features = [
21-
"std",
22+
"alloc",
2223
"sink",
2324
] }
2425
tokio-postgres = { version = "0.7.10", optional = true }

src/async_connection_wrapper.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
//! as replacement for the existing connection
1010
//! implementations provided by diesel
1111
12-
use futures_util::Future;
13-
use futures_util::Stream;
12+
use futures_core::Stream;
1413
use futures_util::StreamExt;
14+
use std::future::Future;
1515
use std::pin::Pin;
1616

1717
/// This is a helper trait that allows to customize the

src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,11 @@ use diesel::connection::{CacheSize, Instrumentation};
7878
use diesel::query_builder::{AsQuery, QueryFragment, QueryId};
7979
use diesel::row::Row;
8080
use diesel::{ConnectionResult, QueryResult};
81-
use futures_util::future::BoxFuture;
82-
use futures_util::{Future, FutureExt, Stream};
81+
use futures_core::future::BoxFuture;
82+
use futures_core::Stream;
83+
use futures_util::FutureExt;
8384
use std::fmt::Debug;
85+
use std::future::Future;
8486

8587
pub use scoped_futures;
8688
use scoped_futures::{ScopedBoxFuture, ScopedFutureExt};
@@ -322,15 +324,15 @@ pub trait AsyncConnection: SimpleAsyncConnection + Sized + Send {
322324
.map_err(|_| diesel::result::Error::RollbackTransaction)
323325
.and_then(move |r| {
324326
let _ = user_result_tx.send(r);
325-
futures_util::future::ready(Err(diesel::result::Error::RollbackTransaction))
327+
std::future::ready(Err(diesel::result::Error::RollbackTransaction))
326328
})
327329
.scope_boxed()
328330
})
329331
.then(move |_r| {
330332
let r = user_result_rx
331333
.try_recv()
332334
.expect("Transaction did not succeed");
333-
futures_util::future::ready(r)
335+
std::future::ready(r)
334336
})
335337
}
336338

src/mysql/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ use diesel::query_builder::QueryBuilder;
1111
use diesel::query_builder::{bind_collector::RawBytesBindCollector, QueryFragment, QueryId};
1212
use diesel::result::{ConnectionError, ConnectionResult};
1313
use diesel::QueryResult;
14-
use futures_util::future::BoxFuture;
15-
use futures_util::stream::{self, BoxStream};
16-
use futures_util::{Future, FutureExt, StreamExt, TryStreamExt};
14+
use futures_core::future::BoxFuture;
15+
use futures_core::stream::BoxStream;
16+
use futures_util::stream;
17+
use futures_util::{FutureExt, StreamExt, TryStreamExt};
1718
use mysql_async::prelude::Queryable;
1819
use mysql_async::{Opts, OptsBuilder, Statement};
20+
use std::future::Future;
1921

2022
mod error_helper;
2123
mod row;

src/pg/mod.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ use diesel::query_builder::bind_collector::RawBytesBindCollector;
2222
use diesel::query_builder::{AsQuery, QueryBuilder, QueryFragment, QueryId};
2323
use diesel::result::{DatabaseErrorKind, Error};
2424
use diesel::{ConnectionError, ConnectionResult, QueryResult};
25-
use futures_util::future::BoxFuture;
25+
use futures_core::future::BoxFuture;
26+
use futures_core::stream::BoxStream;
2627
use futures_util::future::Either;
27-
use futures_util::stream::{BoxStream, TryStreamExt};
28+
use futures_util::stream::TryStreamExt;
2829
use futures_util::TryFutureExt;
29-
use futures_util::{Future, FutureExt, StreamExt};
30+
use futures_util::{FutureExt, StreamExt};
3031
use std::collections::{HashMap, HashSet};
32+
use std::future::Future;
3133
use std::sync::Arc;
3234
use tokio::sync::broadcast;
3335
use tokio::sync::oneshot;
@@ -443,10 +445,11 @@ impl AsyncPgConnection {
443445
async fn set_config_options(&mut self) -> QueryResult<()> {
444446
use crate::run_query_dsl::RunQueryDsl;
445447

446-
futures_util::try_join!(
448+
futures_util::future::try_join(
447449
diesel::sql_query("SET TIME ZONE 'UTC'").execute(self),
448450
diesel::sql_query("SET CLIENT_ENCODING TO 'UTF8'").execute(self),
449-
)?;
451+
)
452+
.await?;
450453
Ok(())
451454
}
452455

src/pooled_connection/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use crate::{TransactionManager, UpdateAndFetchResults};
1010
use diesel::associations::HasTable;
1111
use diesel::connection::{CacheSize, Instrumentation};
1212
use diesel::QueryResult;
13-
use futures_util::future::BoxFuture;
14-
use futures_util::{future, FutureExt};
13+
use futures_core::future::BoxFuture;
14+
use futures_util::FutureExt;
1515
use std::borrow::Cow;
1616
use std::fmt;
1717
use std::future::Future;
@@ -47,11 +47,10 @@ impl std::error::Error for PoolError {}
4747

4848
/// Type of the custom setup closure passed to [`ManagerConfig::custom_setup`]
4949
pub type SetupCallback<C> =
50-
Box<dyn Fn(&str) -> future::BoxFuture<diesel::ConnectionResult<C>> + Send + Sync>;
50+
Box<dyn Fn(&str) -> BoxFuture<diesel::ConnectionResult<C>> + Send + Sync>;
5151

5252
/// Type of the recycle check callback for the [`RecyclingMethod::CustomFunction`] variant
53-
pub type RecycleCheckCallback<C> =
54-
dyn Fn(&mut C) -> future::BoxFuture<QueryResult<()>> + Send + Sync;
53+
pub type RecycleCheckCallback<C> = dyn Fn(&mut C) -> BoxFuture<QueryResult<()>> + Send + Sync;
5554

5655
/// Possible methods of how a connection is recycled.
5756
#[derive(Default)]

src/run_query_dsl/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ use diesel::associations::HasTable;
33
use diesel::query_builder::IntoUpdateTarget;
44
use diesel::result::QueryResult;
55
use diesel::AsChangeset;
6-
use futures_util::future::BoxFuture;
7-
use futures_util::{future, stream, FutureExt, Stream, StreamExt, TryFutureExt, TryStreamExt};
6+
use futures_core::future::BoxFuture;
7+
use futures_core::Stream;
8+
use futures_util::{future, stream, FutureExt, StreamExt, TryFutureExt, TryStreamExt};
89
use std::future::Future;
910
use std::pin::Pin;
1011

@@ -398,7 +399,7 @@ pub trait RunQueryDsl<Conn>: Sized {
398399
/// .await?
399400
/// .try_fold(Vec::new(), |mut acc, item| {
400401
/// acc.push(item);
401-
/// futures_util::future::ready(Ok(acc))
402+
/// std::future::ready(Ok(acc))
402403
/// })
403404
/// .await?;
404405
/// assert_eq!(vec!["Sean", "Tess"], data);
@@ -427,7 +428,7 @@ pub trait RunQueryDsl<Conn>: Sized {
427428
/// .await?
428429
/// .try_fold(Vec::new(), |mut acc, item| {
429430
/// acc.push(item);
430-
/// futures_util::future::ready(Ok(acc))
431+
/// std::future::ready(Ok(acc))
431432
/// })
432433
/// .await?;
433434
/// let expected_data = vec![
@@ -467,7 +468,7 @@ pub trait RunQueryDsl<Conn>: Sized {
467468
/// .await?
468469
/// .try_fold(Vec::new(), |mut acc, item| {
469470
/// acc.push(item);
470-
/// futures_util::future::ready(Ok(acc))
471+
/// std::future::ready(Ok(acc))
471472
/// })
472473
/// .await?;
473474
/// let expected_data = vec![

src/stmt_cache.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
use diesel::connection::statement_cache::{MaybeCached, StatementCallbackReturnType};
22
use diesel::QueryResult;
3-
use futures_util::{future, FutureExt, TryFutureExt};
4-
use std::future::Future;
3+
use futures_core::future::BoxFuture;
4+
use futures_util::future::Either;
5+
use futures_util::{FutureExt, TryFutureExt};
6+
use std::future::{self, Future};
57

68
pub(crate) struct CallbackHelper<F>(pub(crate) F);
79

8-
type PrepareFuture<'a, C, S> = future::Either<
10+
type PrepareFuture<'a, C, S> = Either<
911
future::Ready<QueryResult<(MaybeCached<'a, S>, C)>>,
10-
future::BoxFuture<'a, QueryResult<(MaybeCached<'a, S>, C)>>,
12+
BoxFuture<'a, QueryResult<(MaybeCached<'a, S>, C)>>,
1113
>;
1214

1315
impl<S, F, C> StatementCallbackReturnType<S, C> for CallbackHelper<F>
@@ -18,22 +20,22 @@ where
1820
type Return<'a> = PrepareFuture<'a, C, S>;
1921

2022
fn from_error<'a>(e: diesel::result::Error) -> Self::Return<'a> {
21-
future::Either::Left(future::ready(Err(e)))
23+
Either::Left(future::ready(Err(e)))
2224
}
2325

2426
fn map_to_no_cache<'a>(self) -> Self::Return<'a>
2527
where
2628
Self: 'a,
2729
{
28-
future::Either::Right(
30+
Either::Right(
2931
self.0
3032
.map_ok(|(stmt, conn)| (MaybeCached::CannotCache(stmt), conn))
3133
.boxed(),
3234
)
3335
}
3436

3537
fn map_to_cache(stmt: &mut S, conn: C) -> Self::Return<'_> {
36-
future::Either::Left(future::ready(Ok((MaybeCached::Cached(stmt), conn))))
38+
Either::Left(future::ready(Ok((MaybeCached::Cached(stmt), conn))))
3739
}
3840

3941
fn register_cache<'a>(
@@ -43,7 +45,7 @@ where
4345
where
4446
Self: 'a,
4547
{
46-
future::Either::Right(
48+
Either::Right(
4749
self.0
4850
.map_ok(|(stmt, conn)| (MaybeCached::Cached(callback(stmt)), conn))
4951
.boxed(),

src/sync_connection_wrapper/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//!
77
//! * using a sync Connection implementation in async context
88
//! * using the same code base for async crates needing multiple backends
9-
use futures_util::future::BoxFuture;
9+
use futures_core::future::BoxFuture;
1010
use std::error::Error;
1111

1212
#[cfg(feature = "sqlite")]
@@ -100,7 +100,7 @@ mod implementation {
100100
};
101101
use diesel::row::IntoOwnedRow;
102102
use diesel::{ConnectionResult, QueryResult};
103-
use futures_util::stream::BoxStream;
103+
use futures_core::stream::BoxStream;
104104
use futures_util::{FutureExt, StreamExt, TryFutureExt};
105105
use std::marker::PhantomData;
106106
use std::sync::{Arc, Mutex};

0 commit comments

Comments
 (0)