Reduce dependency on futures-util (#3358)

This commit is contained in:
Paolo Barbolini
2025-05-25 09:39:35 +02:00
committed by GitHub
parent d0aff24c85
commit 869ba86e51
32 changed files with 50 additions and 67 deletions
+1 -1
View File
@@ -6,7 +6,7 @@ publish = false
[dependencies]
axum = { path = "../../axum", features = ["ws"] }
futures = "0.3"
futures-util = { version = "0.3", default-features = false, features = ["sink", "std"] }
tokio = { version = "1", features = ["full"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
+1 -1
View File
@@ -15,7 +15,7 @@ use axum::{
routing::get,
Router,
};
use futures::{sink::SinkExt, stream::StreamExt};
use futures_util::{sink::SinkExt, stream::StreamExt};
use std::{
collections::HashSet,
sync::{Arc, Mutex},
@@ -5,7 +5,6 @@
//! ```
use axum::{extract::Request, routing::get, Router};
use futures_util::pin_mut;
use hyper::body::Incoming;
use hyper_util::rt::{TokioExecutor, TokioIo};
use std::path::PathBuf;
@@ -43,7 +42,6 @@ async fn main() {
info!("HTTPS server listening on {bind}. To contact curl -k https://localhost:3000");
let app = Router::new().route("/", get(handler));
pin_mut!(tcp_listener);
loop {
let tower_service = app.clone();
let tls_acceptor = tls_acceptor.clone();
-3
View File
@@ -5,7 +5,6 @@
//! ```
use axum::{http::Request, routing::get, Router};
use futures_util::pin_mut;
use hyper::body::Incoming;
use hyper_util::rt::{TokioExecutor, TokioIo};
use openssl::ssl::{Ssl, SslAcceptor, SslFiletype, SslMethod};
@@ -55,8 +54,6 @@ async fn main() {
info!("HTTPS server listening on {bind}. To contact curl -k https://localhost:3000");
let app = Router::new().route("/", get(handler));
pin_mut!(tcp_listener);
loop {
let tower_service = app.clone();
let tls_acceptor = tls_acceptor.clone();
-2
View File
@@ -5,7 +5,6 @@
//! ```
use axum::{extract::Request, routing::get, Router};
use futures_util::pin_mut;
use hyper::body::Incoming;
use hyper_util::rt::{TokioExecutor, TokioIo};
use std::{
@@ -47,7 +46,6 @@ async fn main() {
info!("HTTPS server listening on {bind}. To contact curl -k https://localhost:3000");
let app = Router::new().route("/", get(handler));
pin_mut!(tcp_listener);
loop {
let tower_service = app.clone();
let tls_acceptor = tls_acceptor.clone();
+1 -1
View File
@@ -7,7 +7,7 @@ publish = false
[dependencies]
axum = { path = "../../axum" }
axum-extra = { path = "../../axum-extra", features = ["typed-header"] }
futures = "0.3"
futures-util = { version = "0.3", default-features = false, features = ["sink", "std"] }
headers = "0.4"
tokio = { version = "1.0", features = ["full"] }
tokio-stream = "0.1"
+1 -1
View File
@@ -14,7 +14,7 @@ use axum::{
Router,
};
use axum_extra::TypedHeader;
use futures::stream::{self, Stream};
use futures_util::stream::{self, Stream};
use std::{convert::Infallible, path::PathBuf, time::Duration};
use tokio_stream::StreamExt as _;
use tower_http::{services::ServeDir, trace::TraceLayer};
+1 -1
View File
@@ -6,7 +6,7 @@ publish = false
[dependencies]
axum = { path = "../../axum", features = ["multipart"] }
futures = "0.3"
futures-util = { version = "0.3", default-features = false, features = ["sink", "std"] }
tokio = { version = "1.0", features = ["full"] }
tokio-util = { version = "0.7", features = ["io"] }
tracing = "0.1"
+3 -4
View File
@@ -12,8 +12,8 @@ use axum::{
routing::{get, post},
BoxError, Router,
};
use futures::{Stream, TryStreamExt};
use std::io;
use futures_util::{Stream, TryStreamExt};
use std::{io, pin::pin};
use tokio::{fs::File, io::BufWriter};
use tokio_util::io::StreamReader;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
@@ -112,8 +112,7 @@ where
async {
// Convert the stream into an `AsyncRead`.
let body_with_io_error = stream.map_err(io::Error::other);
let body_reader = StreamReader::new(body_with_io_error);
futures::pin_mut!(body_reader);
let mut body_reader = pin!(StreamReader::new(body_with_io_error));
// Create the file. `File` implements `AsyncWrite`.
let path = std::path::Path::new(UPLOADS_DIRECTORY).join(path);
+2 -1
View File
@@ -6,6 +6,7 @@ publish = false
[dependencies]
axum = { path = "../../axum", features = ["ws"] }
futures = "0.3"
futures-channel = "0.3"
futures-util = { version = "0.3", default-features = false, features = ["sink", "std"] }
tokio = { version = "1.0", features = ["full"] }
tokio-tungstenite = "0.26"
+3 -3
View File
@@ -13,7 +13,7 @@ use axum::{
routing::get,
Router,
};
use futures::{Sink, SinkExt, Stream, StreamExt};
use futures_util::{Sink, SinkExt, Stream, StreamExt};
#[tokio::main]
async fn main() {
@@ -131,8 +131,8 @@ mod tests {
async fn unit_test() {
// Need to use "futures" channels rather than "tokio" channels as they implement `Sink` and
// `Stream`
let (socket_write, mut test_rx) = futures::channel::mpsc::channel(1024);
let (mut test_tx, socket_read) = futures::channel::mpsc::channel(1024);
let (socket_write, mut test_rx) = futures_channel::mpsc::channel(1024);
let (mut test_tx, socket_read) = futures_channel::mpsc::channel(1024);
tokio::spawn(unit_testable_handle_socket(socket_write, socket_read));
-1
View File
@@ -15,7 +15,6 @@ path = "src/client.rs"
[dependencies]
axum = { path = "../../axum", features = ["ws"] }
axum-extra = { path = "../../axum-extra", features = ["typed-header"] }
futures = "0.3"
futures-util = { version = "0.3", default-features = false, features = ["sink", "std"] }
headers = "0.4"
tokio = { version = "1.0", features = ["full"] }
+3 -5
View File
@@ -10,10 +10,10 @@
//! websocket server and how the client-side and server-side code can be quite similar.
//!
use futures_util::stream::FuturesUnordered;
use futures_util::{SinkExt, StreamExt};
use std::ops::ControlFlow;
use std::time::Instant;
use tokio::task::JoinSet;
use tokio_tungstenite::tungstenite::Utf8Bytes;
// we will use tungstenite for websocket client impl (same library as what axum is using)
@@ -29,12 +29,10 @@ const SERVER: &str = "ws://127.0.0.1:3000/ws";
async fn main() {
let start_time = Instant::now();
//spawn several clients that will concurrently talk to the server
let mut clients = (0..N_CLIENTS)
.map(|cli| tokio::spawn(spawn_client(cli)))
.collect::<FuturesUnordered<_>>();
let mut clients = (0..N_CLIENTS).map(spawn_client).collect::<JoinSet<_>>();
//wait for all our clients to exit
while clients.next().await.is_some() {}
while clients.join_next().await.is_some() {}
let end_time = Instant::now();
+1 -1
View File
@@ -39,7 +39,7 @@ use axum::extract::connect_info::ConnectInfo;
use axum::extract::ws::CloseFrame;
//allows to split the websocket stream into separate TX and RX branches
use futures::{sink::SinkExt, stream::StreamExt};
use futures_util::{sink::SinkExt, stream::StreamExt};
#[tokio::main]
async fn main() {