Skip to content

Fix pipeline, clippy lints, and formatting errors #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
with:
rust-version: ${{ matrix.rust }}
- name: Test
run: cargo test
run: cargo test --all-features

publish-docs:
if: github.ref == 'refs/heads/main'
Expand All @@ -97,7 +97,7 @@ jobs:
- uses: actions/checkout@v2
- name: Generate Docs
run: |
cargo doc --no-deps
cargo doc --no-deps --all-features
echo "<meta http-equiv=refresh content=0;url=`echo ${{ github.repository }} | cut -d / -f 2 | tr '-' '_'`/index.html>" > target/doc/index.html
- name: Publish
uses: peaceiris/actions-gh-pages@v3
Expand All @@ -118,4 +118,4 @@ jobs:
shell: bash
run: cargo publish --token ${{ env.CRATES_TOKEN }}
env:
CRATES_TOKEN: ${{ secrets.CRATES_TOKEN }}
CRATES_TOKEN: ${{ secrets.CRATES_TOKEN }}
22 changes: 13 additions & 9 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -23,10 +23,7 @@ pin_project! {
}

impl UnixStream {
async fn connect<P>(path: P) -> std::io::Result<Self>
where
P: AsRef<Path>,
{
async fn connect(path: impl AsRef<Path>) -> io::Result<Self> {
let unix_stream = tokio::net::UnixStream::connect(path).await?;
Ok(Self { unix_stream })
}
Expand All @@ -40,9 +37,11 @@ impl tokio::io::AsyncWrite for UnixStream {
) -> Poll<Result<usize, io::Error>> {
self.project().unix_stream.poll_write(cx, buf)
}

fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), io::Error>> {
self.project().unix_stream.poll_flush(cx)
}

fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), io::Error>> {
self.project().unix_stream.poll_shutdown(cx)
}
Expand Down Expand Up @@ -80,16 +79,20 @@ impl Unpin for UnixConnector {}

impl Service<Uri> for UnixConnector {
type Response = UnixStream;
type Error = std::io::Error;
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>;
type Error = io::Error;
#[allow(clippy::type_complexity)]
type Future =
Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + 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<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
}
Expand All @@ -101,7 +104,7 @@ impl Connection for UnixStream {
}
}

fn parse_socket_path(uri: Uri) -> Result<std::path::PathBuf, io::Error> {
fn parse_socket_path(uri: &Uri) -> Result<PathBuf, io::Error> {
if uri.scheme_str() != Some("unix") {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
Expand Down Expand Up @@ -138,6 +141,7 @@ pub trait UnixClientExt {
///
/// let client = Client::unix();
/// ```
#[must_use]
fn unix() -> Client<UnixConnector, Body> {
Client::builder().build(UnixConnector)
}
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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/).
Expand Down
7 changes: 6 additions & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Path>) -> Result<Self, std::io::Error> {
let listener = UnixListener::bind(path)?;

Expand All @@ -50,7 +53,8 @@ pub(crate) mod conn {
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Option<Result<Self::Conn, Self::Error>>> {
self.listener.poll_accept(cx)?
self.listener
.poll_accept(cx)?
.map(|(conn, _)| Some(Ok(conn)))
}
}
Expand Down Expand Up @@ -84,6 +88,7 @@ pub(crate) mod conn {
/// ```
pub trait UnixServerExt {
/// Convenience method for constructing a Server listening on a Unix socket.
#[allow(clippy::missing_errors_doc)]
fn bind_unix(path: impl AsRef<Path>) -> Result<Builder<SocketIncoming>, io::Error>;
}

Expand Down
3 changes: 3 additions & 0 deletions src/uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ pub struct Uri {

impl Uri {
/// Create a new `[Uri]` from a socket address and a path
///
/// # Panics
/// Will panic if path is not absolute and/or a malformed path string.
pub fn new(socket: impl AsRef<Path>, path: &str) -> Self {
let host = hex::encode(socket.as_ref().to_string_lossy().as_bytes());
let host_str = format!("unix://{}:0{}", host, path);
Expand Down