diff --git a/Cargo.toml b/Cargo.toml index a96a7f1..fc2c070 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,15 +12,32 @@ edition = "2018" [dependencies] 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" -futures-util = "0.3" +hyper = "0.14" +tokio = { version = "1.0", features = ["net"] } +pin-project-lite = "0.2" [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"] diff --git a/src/client.rs b/src/client.rs index a54e762..796cbb8 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,24 +1,25 @@ -use futures_util::future::BoxFuture; use hex::FromHex; use hyper::{ client::connect::{Connected, Connection}, service::Service, Body, Client, Uri, }; -use pin_project::pin_project; +use pin_project_lite::pin_project; use std::{ io, + future::Future, path::{Path, PathBuf}, pin::Pin, task::{Context, Poll}, }; 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 { @@ -80,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 0bbc549..6c9630a 100644 --- a/src/server.rs +++ b/src/server.rs @@ -5,9 +5,8 @@ use hyper::server::{Builder, Server}; 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 +15,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 { @@ -50,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))) } }