Skip to content

Commit

Permalink
Add lints, impl Debug for reader and writer
Browse files Browse the repository at this point in the history
  • Loading branch information
sagebind committed Jul 18, 2019
1 parent 65cc50b commit 636aa13
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
11 changes: 11 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
14 changes: 7 additions & 7 deletions src/pipe/chunked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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<Cursor<Vec<u8>>>,

Expand All @@ -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<io::Result<usize>> {
fn poll_read(mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8]) -> Poll<io::Result<usize>> {
// 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() {
Expand Down Expand Up @@ -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<Cursor<Vec<u8>>>,

Expand All @@ -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<io::Result<usize>> {
fn poll_write(mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8]) -> Poll<io::Result<usize>> {
// 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.
Expand Down Expand Up @@ -177,11 +177,11 @@ impl AsyncWrite for Writer {
}
}

fn poll_flush(self: Pin<&mut Self>, _: &mut Context) -> Poll<io::Result<()>> {
fn poll_flush(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<io::Result<()>> {
Poll::Ready(Ok(()))
}

fn poll_close(mut self: Pin<&mut Self>, _: &mut Context) -> Poll<io::Result<()>> {
fn poll_close(mut self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<io::Result<()>> {
self.buf_stream_tx.close_channel();
Poll::Ready(Ok(()))
}
Expand Down
21 changes: 17 additions & 4 deletions src/pipe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//! and writing.
use futures::prelude::*;
use std::fmt;
use std::io;
use std::pin::Pin;
use std::task::*;
Expand Down Expand Up @@ -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<io::Result<usize>> {
fn poll_read(mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8]) -> Poll<io::Result<usize>> {
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<io::Result<usize>> {
fn poll_write(mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8]) -> Poll<io::Result<usize>> {
Pin::new(&mut self.inner).poll_write(cx, buf)
}

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

fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<io::Result<()>> {
fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
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")
}
}

0 comments on commit 636aa13

Please sign in to comment.