From 0e5b23c4747c659216eba085a43b09f0dc67c903 Mon Sep 17 00:00:00 2001 From: Jens Reidel Date: Thu, 7 Nov 2024 15:28:49 +0100 Subject: [PATCH] capnp-futures: Use more fine-grained futures-* deps The large futures crate pulls in a bunch of sub-crates that capnp-futures does not need. We can instead use only the subcrates that are actually required. Signed-off-by: Jens Reidel --- capnp-futures/Cargo.toml | 7 ++++++- capnp-futures/src/read_stream.rs | 6 +++--- capnp-futures/src/serialize.rs | 3 +-- capnp-futures/src/serialize_packed.rs | 2 +- capnp-futures/src/write_queue.rs | 12 +++++++----- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/capnp-futures/Cargo.toml b/capnp-futures/Cargo.toml index 2fe18ea36..aee79283a 100644 --- a/capnp-futures/Cargo.toml +++ b/capnp-futures/Cargo.toml @@ -14,11 +14,16 @@ keywords = ["async"] [dependencies] capnp = { version = "0.20.0", path = "../capnp" } -[dependencies.futures] +[dependencies.futures-channel] version = "0.3.0" default-features = false features = ["std"] +[dependencies.futures-util] +version = "0.3.0" +default-features = false +features = ["io", "std"] + [dev-dependencies.futures] version = "0.3.0" default-features = false diff --git a/capnp-futures/src/read_stream.rs b/capnp-futures/src/read_stream.rs index 5059a70f2..8a88fe53c 100644 --- a/capnp-futures/src/read_stream.rs +++ b/capnp-futures/src/read_stream.rs @@ -18,13 +18,13 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -use futures::future::Future; -use futures::stream::Stream; -use futures::AsyncRead; +use std::future::Future; use std::pin::Pin; use std::task::{Context, Poll}; use capnp::{message, Error}; +use futures_util::stream::Stream; +use futures_util::AsyncRead; async fn read_next_message( mut reader: R, diff --git a/capnp-futures/src/serialize.rs b/capnp-futures/src/serialize.rs index e897b7fd6..7a8322e90 100644 --- a/capnp-futures/src/serialize.rs +++ b/capnp-futures/src/serialize.rs @@ -25,8 +25,7 @@ use capnp::serialize::{OwnedSegments, SegmentLengthsBuilder}; use capnp::{message, Error, OutputSegments, Result}; - -use futures::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt}; +use futures_util::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt}; /// Asynchronously reads a message from `reader`. pub async fn read_message( diff --git a/capnp-futures/src/serialize_packed.rs b/capnp-futures/src/serialize_packed.rs index f2d79ab1d..b50179fde 100644 --- a/capnp-futures/src/serialize_packed.rs +++ b/capnp-futures/src/serialize_packed.rs @@ -27,7 +27,7 @@ use std::task::{Context, Poll}; use capnp::serialize::OwnedSegments; use capnp::{message, Result}; -use futures::{AsyncRead, AsyncWrite}; +use futures_util::{AsyncRead, AsyncWrite}; use crate::serialize::AsOutputSegments; diff --git a/capnp-futures/src/write_queue.rs b/capnp-futures/src/write_queue.rs index 1af8216fc..65ad1afa9 100644 --- a/capnp-futures/src/write_queue.rs +++ b/capnp-futures/src/write_queue.rs @@ -18,9 +18,10 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -use futures::channel::oneshot; -use futures::future::Future; -use futures::{AsyncWrite, AsyncWriteExt, StreamExt, TryFutureExt}; +use std::future::Future; + +use futures_channel::oneshot; +use futures_util::{AsyncWrite, AsyncWriteExt, StreamExt, TryFutureExt}; use capnp::Error; @@ -33,12 +34,13 @@ where Message(M, oneshot::Sender), Done(Result<(), Error>, oneshot::Sender<()>), } + /// A handle that allows messages to be sent to a write queue. pub struct Sender where M: AsOutputSegments, { - sender: futures::channel::mpsc::UnboundedSender>, + sender: futures_channel::mpsc::UnboundedSender>, in_flight: std::sync::Arc, } @@ -65,7 +67,7 @@ where W: AsyncWrite + Unpin, M: AsOutputSegments, { - let (tx, mut rx) = futures::channel::mpsc::unbounded::>(); + let (tx, mut rx) = futures_channel::mpsc::unbounded::>(); let in_flight = std::sync::Arc::new(std::sync::atomic::AtomicI32::new(0));