From 636aa13cf772142efd61266182c89fc5c851d0a7 Mon Sep 17 00:00:00 2001 From: "Stephen M. Coakley" Date: Mon, 15 Jul 2019 12:00:57 -0500 Subject: [PATCH] Add lints, impl Debug for reader and writer --- src/lib.rs | 11 +++++++++++ src/pipe/chunked.rs | 14 +++++++------- src/pipe/mod.rs | 21 +++++++++++++++++---- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 760568b..aa61741 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,6 +8,17 @@ //! //! See the `pipe` module for details. +#![deny(unsafe_code)] +#![warn( + future_incompatible, + missing_debug_implementations, + missing_docs, + rust_2018_idioms, + unreachable_pub, + unused, + clippy::all, +)] + #![cfg_attr(feature = "nightly", feature(async_await))] pub mod pipe; diff --git a/src/pipe/chunked.rs b/src/pipe/chunked.rs index 87785bf..b60dbb1 100644 --- a/src/pipe/chunked.rs +++ b/src/pipe/chunked.rs @@ -37,7 +37,7 @@ use std::pin::Pin; /// If `count` is set to 1, then the pipe is essentially serial, since only the /// reader or writer can operate on the single buffer at one time and cannot be /// run in parallel. -pub fn new(count: usize) -> (Reader, Writer) { +pub(crate) fn new(count: usize) -> (Reader, Writer) { let (mut buf_pool_tx, buf_pool_rx) = mpsc::channel(count); let (buf_stream_tx, buf_stream_rx) = mpsc::channel(count); @@ -61,7 +61,7 @@ pub fn new(count: usize) -> (Reader, Writer) { } /// The reading half of a chunked pipe. -pub struct Reader { +pub(crate) struct Reader { /// A channel of incoming chunks from the writer. buf_pool_tx: mpsc::Sender>>, @@ -73,7 +73,7 @@ pub struct Reader { } impl AsyncRead for Reader { - fn poll_read(mut self: Pin<&mut Self>, cx: &mut Context, buf: &mut [u8]) -> Poll> { + fn poll_read(mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8]) -> Poll> { // Fetch the chunk to read from. If we already have one from a previous // read, use that, otherwise receive the next chunk from the writer. let mut chunk = match self.chunk.take() { @@ -138,7 +138,7 @@ impl AsyncRead for Reader { } /// Writing half of a chunked pipe. -pub struct Writer { +pub(crate) struct Writer { /// A channel of chunks to send to the reader. buf_pool_rx: mpsc::Receiver>>, @@ -147,7 +147,7 @@ pub struct Writer { } impl AsyncWrite for Writer { - fn poll_write(mut self: Pin<&mut Self>, cx: &mut Context, buf: &[u8]) -> Poll> { + fn poll_write(mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8]) -> Poll> { // Attempt to grab an available buffer to write the chunk to. match self.buf_pool_rx.poll_next_unpin(cx) { // Wait for the reader to finish reading a chunk. @@ -177,11 +177,11 @@ impl AsyncWrite for Writer { } } - fn poll_flush(self: Pin<&mut Self>, _: &mut Context) -> Poll> { + fn poll_flush(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll> { Poll::Ready(Ok(())) } - fn poll_close(mut self: Pin<&mut Self>, _: &mut Context) -> Poll> { + fn poll_close(mut self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll> { self.buf_stream_tx.close_channel(); Poll::Ready(Ok(())) } diff --git a/src/pipe/mod.rs b/src/pipe/mod.rs index 6d291cc..bfc89a5 100644 --- a/src/pipe/mod.rs +++ b/src/pipe/mod.rs @@ -4,6 +4,7 @@ //! and writing. use futures::prelude::*; +use std::fmt; use std::io; use std::pin::Pin; use std::task::*; @@ -38,26 +39,38 @@ pub struct PipeReader { } impl AsyncRead for PipeReader { - fn poll_read(mut self: Pin<&mut Self>, cx: &mut Context, buf: &mut [u8]) -> Poll> { + fn poll_read(mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8]) -> Poll> { Pin::new(&mut self.inner).poll_read(cx, buf) } } +impl fmt::Debug for PipeReader { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.pad("PipeReader") + } +} + /// The writing end of an asynchronous pipe. pub struct PipeWriter { inner: chunked::Writer, } impl AsyncWrite for PipeWriter { - fn poll_write(mut self: Pin<&mut Self>, cx: &mut Context, buf: &[u8]) -> Poll> { + fn poll_write(mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8]) -> Poll> { Pin::new(&mut self.inner).poll_write(cx, buf) } - fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll> { + fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { Pin::new(&mut self.inner).poll_flush(cx) } - fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll> { + fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { Pin::new(&mut self.inner).poll_close(cx) } } + +impl fmt::Debug for PipeWriter { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.pad("PipeWriter") + } +}