Skip to content

Further reduce dependency on futures and futures-util #3874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ sqlx-sqlite = { workspace = true, optional = true }
[dev-dependencies]
anyhow = "1.0.52"
time_ = { version = "0.3.2", package = "time" }
futures = "0.3.19"
futures-util = { version = "0.3.19", default-features = false, features = ["alloc"] }
env_logger = "0.11"
async-std = { workspace = true, features = ["attributes"] }
tokio = { version = "1.15.0", features = ["full"] }
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ The `fetch` query finalizer returns a stream-like type that iterates through the

```rust
// provides `try_next`
use futures::TryStreamExt;
use futures_util::TryStreamExt;
// provides `try_get`
use sqlx::Row;

Expand Down
1 change: 0 additions & 1 deletion examples/mysql/todos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ workspace = "../../../"

[dependencies]
anyhow = "1.0"
futures = "0.3"
sqlx = { path = "../../../", features = [ "mysql", "runtime-tokio", "tls-native-tls" ] }
clap = { version = "4", features = ["derive"] }
tokio = { version = "1.20.0", features = ["rt", "macros"]}
1 change: 0 additions & 1 deletion examples/postgres/chat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ workspace = "../../../"

[dependencies]
sqlx = { path = "../../../", features = [ "postgres", "runtime-tokio", "tls-native-tls" ] }
futures = "0.3.1"
tokio = { version = "1.20.0", features = [ "rt-multi-thread", "macros" ] }
ratatui = "0.27.0"
crossterm = "0.27.0"
Expand Down
1 change: 0 additions & 1 deletion examples/postgres/json/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ workspace = "../../../"
[dependencies]
anyhow = "1.0"
dotenvy = "0.15.0"
futures = "0.3"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
sqlx = { path = "../../../", features = [ "runtime-tokio", "postgres", "json" ] }
Expand Down
2 changes: 1 addition & 1 deletion examples/postgres/listen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ workspace = "../../../"

[dependencies]
sqlx = { path = "../../../", features = [ "runtime-tokio", "postgres" ] }
futures = "0.3.1"
futures-util = { version = "0.3.1", default-features = false }
tokio = { version = "1.20.0", features = ["rt-multi-thread", "macros", "time"]}
2 changes: 1 addition & 1 deletion examples/postgres/listen/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use futures::TryStreamExt;
use futures_util::TryStreamExt;
use sqlx::postgres::PgListener;
use sqlx::{Executor, PgPool};
use std::pin::pin;
Expand Down
1 change: 0 additions & 1 deletion examples/postgres/mockable-todos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ workspace = "../../../"

[dependencies]
anyhow = "1.0"
futures = "0.3"
sqlx = { path = "../../../", features = [ "postgres", "runtime-tokio", "tls-native-tls" ] }
clap = { version = "4", features = ["derive"] }
tokio = { version = "1.20.0", features = ["rt", "macros"]}
Expand Down
1 change: 0 additions & 1 deletion examples/postgres/todos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ workspace = "../../../"

[dependencies]
anyhow = "1.0"
futures = "0.3"
sqlx = { path = "../../../", features = [ "postgres", "runtime-tokio", "tls-native-tls" ] }
clap = { version = "4", features = ["derive"] }
tokio = { version = "1.20.0", features = ["rt", "macros"]}
Expand Down
1 change: 0 additions & 1 deletion examples/postgres/transaction/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ workspace = "../../../"

[dependencies]
sqlx = { path = "../../../", features = [ "postgres", "runtime-tokio", "tls-native-tls" ] }
futures = "0.3.1"
tokio = { version = "1.20.0", features = ["rt-multi-thread", "macros"]}
1 change: 0 additions & 1 deletion examples/sqlite/todos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ workspace = "../../../"

[dependencies]
anyhow = "1.0"
futures = "0.3"
sqlx = { path = "../../../", features = [ "sqlite", "runtime-tokio", "tls-native-tls" ] }
clap = { version = "4", features = ["derive"] }
tokio = { version = "1.20.0", features = ["rt", "macros"]}
2 changes: 1 addition & 1 deletion sqlx-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ sqlx = { workspace = true, default-features = false, features = [
"migrate",
"any",
] }
futures = "0.3.19"
futures-util = { version = "0.3.19", features = ["alloc"] }
clap = { version = "4.3.10", features = ["derive", "env", "wrap_help"] }
clap_complete = { version = "4.3.1", optional = true }
chrono = { version = "0.4.19", default-features = false, features = ["clock"] }
Expand Down
3 changes: 2 additions & 1 deletion sqlx-cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::future::Future;
use std::io;
use std::time::Duration;

use anyhow::Result;
use futures::{Future, TryFutureExt};
use futures_util::TryFutureExt;

use sqlx::{AnyConnection, Connection};
use tokio::{select, signal};
Expand Down
2 changes: 1 addition & 1 deletion sqlx-core/src/acquire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ macro_rules! impl_acquire {
self,
) -> futures_core::future::BoxFuture<'c, Result<Self::Connection, $crate::error::Error>>
{
Box::pin(futures_util::future::ok(self))
Box::pin(std::future::ready(Ok(self)))
}

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion sqlx-core/src/any/transaction.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use futures_util::future::BoxFuture;
use futures_core::future::BoxFuture;
use std::borrow::Cow;

use crate::any::{Any, AnyConnection};
Expand Down
12 changes: 7 additions & 5 deletions sqlx-core/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::error::{BoxDynError, Error};
use either::Either;
use futures_core::future::BoxFuture;
use futures_core::stream::BoxStream;
use futures_util::{future, FutureExt, StreamExt, TryFutureExt, TryStreamExt};
use std::fmt::Debug;
use futures_util::{FutureExt, StreamExt, TryFutureExt, TryStreamExt};
use std::{fmt::Debug, future};

/// A type that contains or can provide a database
/// connection to use for executing queries against the database.
Expand Down Expand Up @@ -121,9 +121,11 @@ pub trait Executor<'c>: Send + Debug + Sized {
E: 'q + Execute<'q, Self::Database>,
{
self.fetch_optional(query)
.and_then(|row| match row {
Some(row) => future::ok(row),
None => future::err(Error::RowNotFound),
.and_then(|row| {
future::ready(match row {
Some(row) => Ok(row),
None => Err(Error::RowNotFound),
})
})
.boxed()
}
Expand Down
4 changes: 2 additions & 2 deletions sqlx-core/src/ext/async_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! This was created initially to get around some weird compiler errors we were getting with
//! `async-stream`, and now it'd just be more work to replace.
use std::future::Future;
use std::future::{self, Future};
use std::pin::Pin;
use std::sync::{Arc, Mutex};
use std::task::{Context, Poll};
Expand Down Expand Up @@ -76,7 +76,7 @@ impl<T> Yielder<T> {
//
// Note that because this has no way to schedule a wakeup, this could deadlock the task
// if called in the wrong place.
futures_util::future::poll_fn(|_cx| {
future::poll_fn(|_cx| {
if !yielded {
yielded = true;
Poll::Pending
Expand Down
10 changes: 5 additions & 5 deletions sqlx-core/src/net/tls/tls_rustls.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use futures_util::future;
use std::future;
use std::io::{self, Read, Write};
use std::sync::Arc;
use std::task::{Context, Poll};
use std::task::{ready, Context, Poll};

use rustls::{
client::{
Expand Down Expand Up @@ -33,7 +33,7 @@ impl<S: Socket> RustlsSocket<S> {
loop {
match self.state.complete_io(&mut self.inner) {
Err(e) if e.kind() == io::ErrorKind::WouldBlock => {
futures_util::ready!(self.inner.poll_ready(cx))?;
ready!(self.inner.poll_ready(cx))?;
}
ready => return Poll::Ready(ready.map(|_| ())),
}
Expand Down Expand Up @@ -76,12 +76,12 @@ impl<S: Socket> Socket for RustlsSocket<S> {
self.close_notify_sent = true;
}

futures_util::ready!(self.poll_complete_io(cx))?;
ready!(self.poll_complete_io(cx))?;

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

Poll::Ready(Ok(()))
}
Expand Down
3 changes: 1 addition & 2 deletions sqlx-core/src/net/tls/util.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::net::Socket;

use std::future;
use std::io::{self, Read, Write};
use std::task::{ready, Context, Poll};

use futures_util::future;

pub struct StdSocket<S> {
pub socket: S,
wants_read: bool,
Expand Down
4 changes: 2 additions & 2 deletions sqlx-core/src/pool/connection.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::fmt::{self, Debug, Formatter};
use std::future::{self, Future};
use std::ops::{Deref, DerefMut};
use std::sync::Arc;
use std::time::{Duration, Instant};
Expand All @@ -11,7 +12,6 @@ use crate::error::Error;

use super::inner::{is_beyond_max_lifetime, DecrementSizeGuard, PoolInner};
use crate::pool::options::PoolConnectionMetadata;
use std::future::Future;

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

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

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

#[inline]
Expand Down
3 changes: 1 addition & 2 deletions sqlx-core/src/pool/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crossbeam_queue::ArrayQueue;
use crate::sync::{AsyncSemaphore, AsyncSemaphoreReleaser};

use std::cmp;
use std::future::Future;
use std::future::{self, Future};
use std::pin::pin;
use std::sync::atomic::{AtomicBool, AtomicU32, AtomicUsize, Ordering};
use std::sync::{Arc, RwLock};
Expand All @@ -18,7 +18,6 @@ use std::task::Poll;
use crate::logger::private_level_filter_to_trace_level;
use crate::pool::options::PoolConnectionMetadata;
use crate::private_tracing_dynamic_event;
use futures_util::future::{self};
use futures_util::FutureExt;
use std::time::{Duration, Instant};
use tracing::Level;
Expand Down
4 changes: 2 additions & 2 deletions sqlx-core/src/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ use std::fmt;
use std::future::Future;
use std::pin::{pin, Pin};
use std::sync::Arc;
use std::task::{Context, Poll};
use std::task::{ready, Context, Poll};
use std::time::{Duration, Instant};

use event_listener::EventListener;
Expand Down Expand Up @@ -627,7 +627,7 @@ impl Future for CloseEvent {

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

// `EventListener` doesn't like being polled after it yields, and even if it did it
Expand Down
12 changes: 7 additions & 5 deletions sqlx-core/src/query.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::marker::PhantomData;
use std::{future, marker::PhantomData};

use either::Either;
use futures_core::stream::BoxStream;
use futures_util::{future, StreamExt, TryFutureExt, TryStreamExt};
use futures_util::{StreamExt, TryFutureExt, TryStreamExt};

use crate::arguments::{Arguments, IntoArguments};
use crate::database::{Database, HasStatementCache};
Expand Down Expand Up @@ -459,9 +459,11 @@ where
O: 'e,
{
self.fetch_optional(executor)
.and_then(|row| match row {
Some(row) => future::ok(row),
None => future::err(Error::RowNotFound),
.and_then(|row| {
future::ready(match row {
Some(row) => Ok(row),
None => Err(Error::RowNotFound),
})
})
.await
}
Expand Down
Loading
Loading