From 3f3a2e4eafaa346dec37d25bf079e74ac2e0ff5b Mon Sep 17 00:00:00 2001 From: onalante-msft <89409054+onalante-msft@users.noreply.github.com> Date: Thu, 6 Jan 2022 18:17:14 -0800 Subject: [PATCH 1/4] Switch from pin-project to pin-project-lite --- Cargo.toml | 2 +- src/client.rs | 13 +++++++------ src/server.rs | 13 +++++++------ 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a96a7f1..3d270c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ edition = "2018" hex = "0.4" hyper = { version = "0.14", features = ["server", "client", "http1", "runtime"] } tokio = { version = "1.0", features = ["rt-multi-thread", "net"] } -pin-project = "1.0" +pin-project-lite = "0.2" futures-util = "0.3" [dev-dependencies] diff --git a/src/client.rs b/src/client.rs index a54e762..40eca0d 100644 --- a/src/client.rs +++ b/src/client.rs @@ -5,7 +5,7 @@ use hyper::{ service::Service, Body, Client, Uri, }; -use pin_project::pin_project; +use pin_project_lite::pin_project; use std::{ io, path::{Path, PathBuf}, @@ -14,11 +14,12 @@ use std::{ }; use tokio::io::ReadBuf; -#[pin_project] -#[derive(Debug)] -pub struct UnixStream { - #[pin] - unix_stream: tokio::net::UnixStream, +pin_project! { + #[derive(Debug)] + pub struct UnixStream { + #[pin] + unix_stream: tokio::net::UnixStream, + } } impl UnixStream { diff --git a/src/server.rs b/src/server.rs index 0bbc549..f5b9324 100644 --- a/src/server.rs +++ b/src/server.rs @@ -7,7 +7,7 @@ use conn::SocketIncoming; pub(crate) mod conn { use futures_util::ready; use hyper::server::accept::Accept; - use pin_project::pin_project; + use pin_project_lite::pin_project; use std::{ io, path::Path, @@ -16,11 +16,12 @@ pub(crate) mod conn { }; use tokio::net::{UnixListener, UnixStream}; - /// A stream of connections from binding to a socket. - #[pin_project] - #[derive(Debug)] - pub struct SocketIncoming { - listener: UnixListener, + pin_project! { + /// A stream of connections from binding to a socket. + #[derive(Debug)] + pub struct SocketIncoming { + listener: UnixListener, + } } impl SocketIncoming { From f6b4ccd10d0c12457693f3b4ec41f37834af8a89 Mon Sep 17 00:00:00 2001 From: onalante-msft <89409054+onalante-msft@users.noreply.github.com> Date: Thu, 6 Jan 2022 18:18:19 -0800 Subject: [PATCH 2/4] Match hyperlocal features with hyper features --- Cargo.toml | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3d270c5..7a62b56 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,16 +11,34 @@ readme = "README.md" edition = "2018" [dependencies] +futures-util = "0.3" hex = "0.4" -hyper = { version = "0.14", features = ["server", "client", "http1", "runtime"] } -tokio = { version = "1.0", features = ["rt-multi-thread", "net"] } +hyper = "0.14" +tokio = { version = "1.0", features = ["net"] } pin-project-lite = "0.2" -futures-util = "0.3" [dev-dependencies] -tokio = { version = "1.0", features = ["rt-multi-thread", "net", "macros", "io-std", "io-util"] } +tokio = { version = "1.0", features = ["io-std", "io-util", "macros", "rt-multi-thread"] } [features] -client = [] -server = [] -default = ["client", "server"] +default = [] +client = [ + "hyper/client", + "hyper/http1", +] +server = [ + "hyper/http1", + "hyper/server" +] + +[[example]] +name = "client" +required-features = ["client", "hyper/runtime"] + +[[example]] +name = "server" +required-features = ["server", "hyper/runtime"] + +[[test]] +name = "server_client" +required-features = ["client", "server", "hyper/runtime"] From 4618d6e26b8ab5017e03f6bf2086925fe11e13e2 Mon Sep 17 00:00:00 2001 From: onalante-msft <89409054+onalante-msft@users.noreply.github.com> Date: Thu, 6 Jan 2022 18:29:02 -0800 Subject: [PATCH 3/4] Remove unused futures-util features Cf. softprops/hyperlocal#52. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 7a62b56..2dd260b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ readme = "README.md" edition = "2018" [dependencies] -futures-util = "0.3" +futures-util = { version = "0.3", default-features = false, features = ["alloc"] } hex = "0.4" hyper = "0.14" tokio = { version = "1.0", features = ["net"] } From c95ce37e81f1919b57ee47755732475577598d1f Mon Sep 17 00:00:00 2001 From: onalante-msft <89409054+onalante-msft@users.noreply.github.com> Date: Thu, 6 Jan 2022 18:43:17 -0800 Subject: [PATCH 4/4] Remove futures-util dependency --- Cargo.toml | 1 - src/client.rs | 4 ++-- src/server.rs | 5 ++--- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2dd260b..fc2c070 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,6 @@ readme = "README.md" edition = "2018" [dependencies] -futures-util = { version = "0.3", default-features = false, features = ["alloc"] } hex = "0.4" hyper = "0.14" tokio = { version = "1.0", features = ["net"] } diff --git a/src/client.rs b/src/client.rs index 40eca0d..796cbb8 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,4 +1,3 @@ -use futures_util::future::BoxFuture; use hex::FromHex; use hyper::{ client::connect::{Connected, Connection}, @@ -8,6 +7,7 @@ use hyper::{ use pin_project_lite::pin_project; use std::{ io, + future::Future, path::{Path, PathBuf}, pin::Pin, task::{Context, Poll}, @@ -81,7 +81,7 @@ impl Unpin for UnixConnector {} impl Service for UnixConnector { type Response = UnixStream; type Error = std::io::Error; - type Future = BoxFuture<'static, Result>; + type Future = Pin> + Send + 'static>>; fn call(&mut self, req: Uri) -> Self::Future { let fut = async move { let path = parse_socket_path(req)?; diff --git a/src/server.rs b/src/server.rs index f5b9324..6c9630a 100644 --- a/src/server.rs +++ b/src/server.rs @@ -5,7 +5,6 @@ use hyper::server::{Builder, Server}; use conn::SocketIncoming; pub(crate) mod conn { - use futures_util::ready; use hyper::server::accept::Accept; use pin_project_lite::pin_project; use std::{ @@ -51,8 +50,8 @@ pub(crate) mod conn { self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll>> { - let conn = ready!(self.listener.poll_accept(cx))?.0; - Poll::Ready(Some(Ok(conn))) + self.listener.poll_accept(cx)? + .map(|(conn, _)| Some(Ok(conn))) } }