Replace some more futures_util APIs with std variants (#3874)

This commit is contained in:
Paolo Barbolini
2025-06-16 00:18:39 +02:00
committed by GitHub
parent 90797200ee
commit df47ffedd2
34 changed files with 55 additions and 67 deletions

View File

@@ -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]

View File

@@ -1,4 +1,4 @@
use futures_util::future::BoxFuture;
use futures_core::future::BoxFuture;
use std::borrow::Cow;
use crate::any::{Any, AnyConnection};

View File

@@ -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.
@@ -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()
}

View File

@@ -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};
@@ -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

View File

@@ -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::{
@@ -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(|_| ())),
}
@@ -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(()))
}

View File

@@ -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,

View File

@@ -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};
@@ -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);
@@ -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]

View File

@@ -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};
@@ -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;

View File

@@ -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;
@@ -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

View File

@@ -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};
@@ -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
}

View File

@@ -1,5 +1,6 @@
use std::borrow::Cow;
use std::fmt::{self, Debug, Formatter};
use std::future;
use std::ops::{Deref, DerefMut};
use futures_core::future::BoxFuture;
@@ -247,7 +248,7 @@ impl<'t, DB: Database> crate::acquire::Acquire<'t> for &'t mut Transaction<'_, D
#[inline]
fn acquire(self) -> BoxFuture<'t, Result<Self::Connection, Error>> {
Box::pin(futures_util::future::ok(&mut **self))
Box::pin(future::ready(Ok(&mut **self)))
}
#[inline]