From f185a485f7c7a160f859ce990c2b1b63ec9346c3 Mon Sep 17 00:00:00 2001
From: onalante-msft <89409054+onalante-msft@users.noreply.github.com>
Date: Sun, 9 Jan 2022 18:54:54 -0800
Subject: [PATCH 1/2] Add and fix clippy lints and formatting errors
---
src/client.rs | 22 +++++++++++++---------
src/lib.rs | 1 +
src/server.rs | 7 ++++++-
src/uri.rs | 3 +++
4 files changed, 23 insertions(+), 10 deletions(-)
diff --git a/src/client.rs b/src/client.rs
index 796cbb8..fe96edb 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -6,8 +6,8 @@ use hyper::{
};
use pin_project_lite::pin_project;
use std::{
- io,
future::Future,
+ io,
path::{Path, PathBuf},
pin::Pin,
task::{Context, Poll},
@@ -23,10 +23,7 @@ pin_project! {
}
impl UnixStream {
- async fn connect
(path: P) -> std::io::Result
- where
- P: AsRef,
- {
+ async fn connect(path: impl AsRef) -> io::Result {
let unix_stream = tokio::net::UnixStream::connect(path).await?;
Ok(Self { unix_stream })
}
@@ -40,9 +37,11 @@ impl tokio::io::AsyncWrite for UnixStream {
) -> Poll> {
self.project().unix_stream.poll_write(cx, buf)
}
+
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> {
self.project().unix_stream.poll_flush(cx)
}
+
fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> {
self.project().unix_stream.poll_shutdown(cx)
}
@@ -80,16 +79,20 @@ impl Unpin for UnixConnector {}
impl Service for UnixConnector {
type Response = UnixStream;
- type Error = std::io::Error;
- type Future = Pin> + Send + 'static>>;
+ type Error = io::Error;
+ #[allow(clippy::type_complexity)]
+ type Future =
+ Pin> + Send + 'static>>;
+
fn call(&mut self, req: Uri) -> Self::Future {
let fut = async move {
- let path = parse_socket_path(req)?;
+ let path = parse_socket_path(&req)?;
UnixStream::connect(path).await
};
Box::pin(fut)
}
+
fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll> {
Poll::Ready(Ok(()))
}
@@ -101,7 +104,7 @@ impl Connection for UnixStream {
}
}
-fn parse_socket_path(uri: Uri) -> Result {
+fn parse_socket_path(uri: &Uri) -> Result {
if uri.scheme_str() != Some("unix") {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
@@ -138,6 +141,7 @@ pub trait UnixClientExt {
///
/// let client = Client::unix();
/// ```
+ #[must_use]
fn unix() -> Client {
Client::builder().build(UnixConnector)
}
diff --git a/src/lib.rs b/src/lib.rs
index 48c41b4..0a64652 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -4,6 +4,7 @@
rust_2018_idioms,
missing_docs
)]
+#![warn(clippy::all, clippy::pedantic)]
//! `hyperlocal` provides [Hyper](http://github.com/hyperium/hyper) bindings
//! for [Unix domain sockets](https://github.com/tokio-rs/tokio/tree/master/tokio-net/src/uds/).
diff --git a/src/server.rs b/src/server.rs
index 6c9630a..c477e17 100644
--- a/src/server.rs
+++ b/src/server.rs
@@ -25,6 +25,9 @@ pub(crate) mod conn {
impl SocketIncoming {
/// Creates a new `SocketIncoming` binding to provided socket path.
+ ///
+ /// # Errors
+ /// Refer to [`tokio::net::Listener::bind`](https://docs.rs/tokio/1.15.0/tokio/net/struct.UnixListener.html#method.bind).
pub fn bind(path: impl AsRef) -> Result {
let listener = UnixListener::bind(path)?;
@@ -50,7 +53,8 @@ pub(crate) mod conn {
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll