Skip to content

Commit df47ffe

Browse files
Replace some more futures_util APIs with std variants (#3874)
1 parent 9079720 commit df47ffe

File tree

34 files changed

+55
-67
lines changed

34 files changed

+55
-67
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ sqlx-sqlite = { workspace = true, optional = true }
169169
[dev-dependencies]
170170
anyhow = "1.0.52"
171171
time_ = { version = "0.3.2", package = "time" }
172-
futures = "0.3.19"
172+
futures-util = { version = "0.3.19", default-features = false, features = ["alloc"] }
173173
env_logger = "0.11"
174174
async-std = { workspace = true, features = ["attributes"] }
175175
tokio = { version = "1.15.0", features = ["full"] }

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ The `fetch` query finalizer returns a stream-like type that iterates through the
326326

327327
```rust
328328
// provides `try_next`
329-
use futures::TryStreamExt;
329+
use futures_util::TryStreamExt;
330330
// provides `try_get`
331331
use sqlx::Row;
332332

examples/mysql/todos/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ workspace = "../../../"
66

77
[dependencies]
88
anyhow = "1.0"
9-
futures = "0.3"
109
sqlx = { path = "../../../", features = [ "mysql", "runtime-tokio", "tls-native-tls" ] }
1110
clap = { version = "4", features = ["derive"] }
1211
tokio = { version = "1.20.0", features = ["rt", "macros"]}

examples/postgres/chat/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ workspace = "../../../"
66

77
[dependencies]
88
sqlx = { path = "../../../", features = [ "postgres", "runtime-tokio", "tls-native-tls" ] }
9-
futures = "0.3.1"
109
tokio = { version = "1.20.0", features = [ "rt-multi-thread", "macros" ] }
1110
ratatui = "0.27.0"
1211
crossterm = "0.27.0"

examples/postgres/json/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ workspace = "../../../"
77
[dependencies]
88
anyhow = "1.0"
99
dotenvy = "0.15.0"
10-
futures = "0.3"
1110
serde = { version = "1", features = ["derive"] }
1211
serde_json = "1"
1312
sqlx = { path = "../../../", features = [ "runtime-tokio", "postgres", "json" ] }

examples/postgres/listen/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ workspace = "../../../"
66

77
[dependencies]
88
sqlx = { path = "../../../", features = [ "runtime-tokio", "postgres" ] }
9-
futures = "0.3.1"
9+
futures-util = { version = "0.3.1", default-features = false }
1010
tokio = { version = "1.20.0", features = ["rt-multi-thread", "macros", "time"]}

examples/postgres/listen/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use futures::TryStreamExt;
1+
use futures_util::TryStreamExt;
22
use sqlx::postgres::PgListener;
33
use sqlx::{Executor, PgPool};
44
use std::pin::pin;

examples/postgres/mockable-todos/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ workspace = "../../../"
66

77
[dependencies]
88
anyhow = "1.0"
9-
futures = "0.3"
109
sqlx = { path = "../../../", features = [ "postgres", "runtime-tokio", "tls-native-tls" ] }
1110
clap = { version = "4", features = ["derive"] }
1211
tokio = { version = "1.20.0", features = ["rt", "macros"]}

examples/postgres/todos/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ workspace = "../../../"
66

77
[dependencies]
88
anyhow = "1.0"
9-
futures = "0.3"
109
sqlx = { path = "../../../", features = [ "postgres", "runtime-tokio", "tls-native-tls" ] }
1110
clap = { version = "4", features = ["derive"] }
1211
tokio = { version = "1.20.0", features = ["rt", "macros"]}

examples/postgres/transaction/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ workspace = "../../../"
66

77
[dependencies]
88
sqlx = { path = "../../../", features = [ "postgres", "runtime-tokio", "tls-native-tls" ] }
9-
futures = "0.3.1"
109
tokio = { version = "1.20.0", features = ["rt-multi-thread", "macros"]}

examples/sqlite/todos/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ workspace = "../../../"
66

77
[dependencies]
88
anyhow = "1.0"
9-
futures = "0.3"
109
sqlx = { path = "../../../", features = [ "sqlite", "runtime-tokio", "tls-native-tls" ] }
1110
clap = { version = "4", features = ["derive"] }
1211
tokio = { version = "1.20.0", features = ["rt", "macros"]}

sqlx-cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ sqlx = { workspace = true, default-features = false, features = [
3333
"migrate",
3434
"any",
3535
] }
36-
futures = "0.3.19"
36+
futures-util = { version = "0.3.19", features = ["alloc"] }
3737
clap = { version = "4.3.10", features = ["derive", "env", "wrap_help"] }
3838
clap_complete = { version = "4.3.1", optional = true }
3939
chrono = { version = "0.4.19", default-features = false, features = ["clock"] }

sqlx-cli/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
use std::future::Future;
12
use std::io;
23
use std::time::Duration;
34

45
use anyhow::Result;
5-
use futures::{Future, TryFutureExt};
6+
use futures_util::TryFutureExt;
67

78
use sqlx::{AnyConnection, Connection};
89
use tokio::{select, signal};

sqlx-core/src/acquire.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ macro_rules! impl_acquire {
111111
self,
112112
) -> futures_core::future::BoxFuture<'c, Result<Self::Connection, $crate::error::Error>>
113113
{
114-
Box::pin(futures_util::future::ok(self))
114+
Box::pin(std::future::ready(Ok(self)))
115115
}
116116

117117
#[inline]

sqlx-core/src/any/transaction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use futures_util::future::BoxFuture;
1+
use futures_core::future::BoxFuture;
22
use std::borrow::Cow;
33

44
use crate::any::{Any, AnyConnection};

sqlx-core/src/executor.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use crate::error::{BoxDynError, Error};
55
use either::Either;
66
use futures_core::future::BoxFuture;
77
use futures_core::stream::BoxStream;
8-
use futures_util::{future, FutureExt, StreamExt, TryFutureExt, TryStreamExt};
9-
use std::fmt::Debug;
8+
use futures_util::{FutureExt, StreamExt, TryFutureExt, TryStreamExt};
9+
use std::{fmt::Debug, future};
1010

1111
/// A type that contains or can provide a database
1212
/// connection to use for executing queries against the database.
@@ -121,9 +121,11 @@ pub trait Executor<'c>: Send + Debug + Sized {
121121
E: 'q + Execute<'q, Self::Database>,
122122
{
123123
self.fetch_optional(query)
124-
.and_then(|row| match row {
125-
Some(row) => future::ok(row),
126-
None => future::err(Error::RowNotFound),
124+
.and_then(|row| {
125+
future::ready(match row {
126+
Some(row) => Ok(row),
127+
None => Err(Error::RowNotFound),
128+
})
127129
})
128130
.boxed()
129131
}

sqlx-core/src/ext/async_stream.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! This was created initially to get around some weird compiler errors we were getting with
44
//! `async-stream`, and now it'd just be more work to replace.
55
6-
use std::future::Future;
6+
use std::future::{self, Future};
77
use std::pin::Pin;
88
use std::sync::{Arc, Mutex};
99
use std::task::{Context, Poll};
@@ -76,7 +76,7 @@ impl<T> Yielder<T> {
7676
//
7777
// Note that because this has no way to schedule a wakeup, this could deadlock the task
7878
// if called in the wrong place.
79-
futures_util::future::poll_fn(|_cx| {
79+
future::poll_fn(|_cx| {
8080
if !yielded {
8181
yielded = true;
8282
Poll::Pending

sqlx-core/src/net/tls/tls_rustls.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use futures_util::future;
1+
use std::future;
22
use std::io::{self, Read, Write};
33
use std::sync::Arc;
4-
use std::task::{Context, Poll};
4+
use std::task::{ready, Context, Poll};
55

66
use rustls::{
77
client::{
@@ -33,7 +33,7 @@ impl<S: Socket> RustlsSocket<S> {
3333
loop {
3434
match self.state.complete_io(&mut self.inner) {
3535
Err(e) if e.kind() == io::ErrorKind::WouldBlock => {
36-
futures_util::ready!(self.inner.poll_ready(cx))?;
36+
ready!(self.inner.poll_ready(cx))?;
3737
}
3838
ready => return Poll::Ready(ready.map(|_| ())),
3939
}
@@ -76,12 +76,12 @@ impl<S: Socket> Socket for RustlsSocket<S> {
7676
self.close_notify_sent = true;
7777
}
7878

79-
futures_util::ready!(self.poll_complete_io(cx))?;
79+
ready!(self.poll_complete_io(cx))?;
8080

8181
// Server can close socket as soon as it receives the connection shutdown request.
8282
// We shouldn't expect it to stick around for the TLS session to close cleanly.
8383
// https://security.stackexchange.com/a/82034
84-
let _ = futures_util::ready!(self.inner.socket.poll_shutdown(cx));
84+
let _ = ready!(self.inner.socket.poll_shutdown(cx));
8585

8686
Poll::Ready(Ok(()))
8787
}

sqlx-core/src/net/tls/util.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use crate::net::Socket;
22

3+
use std::future;
34
use std::io::{self, Read, Write};
45
use std::task::{ready, Context, Poll};
56

6-
use futures_util::future;
7-
87
pub struct StdSocket<S> {
98
pub socket: S,
109
wants_read: bool,

sqlx-core/src/pool/connection.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::fmt::{self, Debug, Formatter};
2+
use std::future::{self, Future};
23
use std::ops::{Deref, DerefMut};
34
use std::sync::Arc;
45
use std::time::{Duration, Instant};
@@ -11,7 +12,6 @@ use crate::error::Error;
1112

1213
use super::inner::{is_beyond_max_lifetime, DecrementSizeGuard, PoolInner};
1314
use crate::pool::options::PoolConnectionMetadata;
14-
use std::future::Future;
1515

1616
const CLOSE_ON_DROP_TIMEOUT: Duration = Duration::from_secs(5);
1717

@@ -183,7 +183,7 @@ impl<'c, DB: Database> crate::acquire::Acquire<'c> for &'c mut PoolConnection<DB
183183

184184
#[inline]
185185
fn acquire(self) -> futures_core::future::BoxFuture<'c, Result<Self::Connection, Error>> {
186-
Box::pin(futures_util::future::ok(&mut **self))
186+
Box::pin(future::ready(Ok(&mut **self)))
187187
}
188188

189189
#[inline]

sqlx-core/src/pool/inner.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crossbeam_queue::ArrayQueue;
99
use crate::sync::{AsyncSemaphore, AsyncSemaphoreReleaser};
1010

1111
use std::cmp;
12-
use std::future::Future;
12+
use std::future::{self, Future};
1313
use std::pin::pin;
1414
use std::sync::atomic::{AtomicBool, AtomicU32, AtomicUsize, Ordering};
1515
use std::sync::{Arc, RwLock};
@@ -18,7 +18,6 @@ use std::task::Poll;
1818
use crate::logger::private_level_filter_to_trace_level;
1919
use crate::pool::options::PoolConnectionMetadata;
2020
use crate::private_tracing_dynamic_event;
21-
use futures_util::future::{self};
2221
use futures_util::FutureExt;
2322
use std::time::{Duration, Instant};
2423
use tracing::Level;

sqlx-core/src/pool/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ use std::fmt;
5959
use std::future::Future;
6060
use std::pin::{pin, Pin};
6161
use std::sync::Arc;
62-
use std::task::{Context, Poll};
62+
use std::task::{ready, Context, Poll};
6363
use std::time::{Duration, Instant};
6464

6565
use event_listener::EventListener;
@@ -627,7 +627,7 @@ impl Future for CloseEvent {
627627

628628
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
629629
if let Some(listener) = &mut self.listener {
630-
futures_core::ready!(listener.poll_unpin(cx));
630+
ready!(listener.poll_unpin(cx));
631631
}
632632

633633
// `EventListener` doesn't like being polled after it yields, and even if it did it

sqlx-core/src/query.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use std::marker::PhantomData;
1+
use std::{future, marker::PhantomData};
22

33
use either::Either;
44
use futures_core::stream::BoxStream;
5-
use futures_util::{future, StreamExt, TryFutureExt, TryStreamExt};
5+
use futures_util::{StreamExt, TryFutureExt, TryStreamExt};
66

77
use crate::arguments::{Arguments, IntoArguments};
88
use crate::database::{Database, HasStatementCache};
@@ -459,9 +459,11 @@ where
459459
O: 'e,
460460
{
461461
self.fetch_optional(executor)
462-
.and_then(|row| match row {
463-
Some(row) => future::ok(row),
464-
None => future::err(Error::RowNotFound),
462+
.and_then(|row| {
463+
future::ready(match row {
464+
Some(row) => Ok(row),
465+
None => Err(Error::RowNotFound),
466+
})
465467
})
466468
.await
467469
}

0 commit comments

Comments
 (0)