Skip to content

Commit

Permalink
Move to pin-project-lite
Browse files Browse the repository at this point in the history
Closes #60
  • Loading branch information
sfackler committed Dec 5, 2019
1 parent 9d905ee commit 434f69b
Show file tree
Hide file tree
Showing 14 changed files with 128 additions and 115 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ bzip2 = { version = "0.3.3" , optional = true }
flate2 = { version = "1.0.11", optional = true }
futures-core = { version = "0.3.0", default-features = false }
futures-io = { version = "0.3.0", default-features = false, features = ["std"], optional = true }
pin-project = "0.4.3"
pin-project-lite = "0.1.1"
libzstd = { version = "0.5.0", optional = true, package = "zstd", default-features = false }
zstd-safe = { version = "2.0.0", optional = true, default-features = false }
memchr = "2.2.1"
Expand Down
17 changes: 9 additions & 8 deletions src/bufread/generic/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::io::Result;
use crate::{codec::Decode, util::PartialBuffer};
use futures_core::ready;
use futures_io::{AsyncBufRead, AsyncRead};
use pin_project::pin_project;
use pin_project_lite::pin_project;

#[derive(Debug)]
enum State {
Expand All @@ -16,13 +16,14 @@ enum State {
Done,
}

#[pin_project]
#[derive(Debug)]
pub struct Decoder<R: AsyncBufRead, D: Decode> {
#[pin]
reader: R,
decoder: D,
state: State,
pin_project! {
#[derive(Debug)]
pub struct Decoder<R: AsyncBufRead, D: Decode> {
#[pin]
reader: R,
decoder: D,
state: State,
}
}

impl<R: AsyncBufRead, D: Decode> Decoder<R, D> {
Expand Down
17 changes: 9 additions & 8 deletions src/bufread/generic/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::io::Result;
use crate::{codec::Encode, util::PartialBuffer};
use futures_core::ready;
use futures_io::{AsyncBufRead, AsyncRead};
use pin_project::pin_project;
use pin_project_lite::pin_project;

#[derive(Debug)]
enum State {
Expand All @@ -16,13 +16,14 @@ enum State {
Done,
}

#[pin_project]
#[derive(Debug)]
pub struct Encoder<R: AsyncBufRead, E: Encode> {
#[pin]
reader: R,
encoder: E,
state: State,
pin_project! {
#[derive(Debug)]
pub struct Encoder<R: AsyncBufRead, E: Encode> {
#[pin]
reader: R,
encoder: E,
state: State,
}
}

impl<R: AsyncBufRead, E: Encode> Encoder<R, E> {
Expand Down
19 changes: 10 additions & 9 deletions src/bufread/macros/decoder.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
macro_rules! decoder {
($(#[$attr:meta])* $name:ident) => {
$(#[$attr])*
#[pin_project::pin_project]
#[derive(Debug)]
///
/// This structure implements an [`AsyncRead`](futures_io::AsyncRead) interface and will
/// read compressed data from an underlying stream and emit a stream of uncompressed data.
pub struct $name<R: futures_io::AsyncBufRead> {
#[pin]
inner: crate::bufread::Decoder<R, crate::codec::$name>,
pin_project_lite::pin_project! {
$(#[$attr])*
#[derive(Debug)]
///
/// This structure implements an [`AsyncRead`](futures_io::AsyncRead) interface and will
/// read compressed data from an underlying stream and emit a stream of uncompressed data.
pub struct $name<R: futures_io::AsyncBufRead> {
#[pin]
inner: crate::bufread::Decoder<R, crate::codec::$name>,
}
}

impl<R: futures_io::AsyncBufRead> $name<R> {
Expand Down
19 changes: 10 additions & 9 deletions src/bufread/macros/encoder.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
macro_rules! encoder {
($(#[$attr:meta])* $name:ident<$inner:ident> $({ $($constructor:tt)* })*) => {
$(#[$attr])*
#[pin_project::pin_project]
#[derive(Debug)]
///
/// This structure implements an [`AsyncRead`](futures_io::AsyncRead) interface and will
/// read uncompressed data from an underlying stream and emit a stream of compressed data.
pub struct $name<$inner: futures_io::AsyncBufRead> {
#[pin]
inner: crate::bufread::Encoder<$inner, crate::codec::$name>,
pin_project_lite::pin_project! {
$(#[$attr])*
#[derive(Debug)]
///
/// This structure implements an [`AsyncRead`](futures_io::AsyncRead) interface and will
/// read uncompressed data from an underlying stream and emit a stream of compressed data.
pub struct $name<$inner: futures_io::AsyncBufRead> {
#[pin]
inner: crate::bufread::Encoder<$inner, crate::codec::$name>,
}
}

impl<$inner: futures_io::AsyncBufRead> $name<$inner> {
Expand Down
21 changes: 11 additions & 10 deletions src/stream/generic/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
use crate::{codec::Decode, util::PartialBuffer};
use bytes::{Bytes, BytesMut};
use futures_core::{ready, stream::Stream};
use pin_project::pin_project;
use pin_project_lite::pin_project;

const OUTPUT_BUFFER_SIZE: usize = 8_000;

Expand All @@ -21,15 +21,16 @@ enum State {
Invalid,
}

#[pin_project]
#[derive(Debug)]
pub struct Decoder<S: Stream<Item = Result<Bytes>>, D: Decode> {
#[pin]
stream: S,
decoder: D,
state: State,
input: Bytes,
output: BytesMut,
pin_project! {
#[derive(Debug)]
pub struct Decoder<S: Stream<Item = Result<Bytes>>, D: Decode> {
#[pin]
stream: S,
decoder: D,
state: State,
input: Bytes,
output: BytesMut,
}
}

impl<S: Stream<Item = Result<Bytes>>, D: Decode> Decoder<S, D> {
Expand Down
21 changes: 11 additions & 10 deletions src/stream/generic/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
use crate::{codec::Encode, util::PartialBuffer};
use bytes::{Bytes, BytesMut};
use futures_core::{ready, stream::Stream};
use pin_project::pin_project;
use pin_project_lite::pin_project;

const OUTPUT_BUFFER_SIZE: usize = 8_000;

Expand All @@ -21,15 +21,16 @@ enum State {
Invalid,
}

#[pin_project]
#[derive(Debug)]
pub struct Encoder<S: Stream<Item = Result<Bytes>>, E: Encode> {
#[pin]
stream: S,
encoder: E,
state: State,
input: Bytes,
output: BytesMut,
pin_project! {
#[derive(Debug)]
pub struct Encoder<S: Stream<Item = Result<Bytes>>, E: Encode> {
#[pin]
stream: S,
encoder: E,
state: State,
input: Bytes,
output: BytesMut,
}
}

impl<S: Stream<Item = Result<Bytes>>, E: Encode> Encoder<S, E> {
Expand Down
19 changes: 10 additions & 9 deletions src/stream/macros/decoder.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
macro_rules! decoder {
($(#[$attr:meta])* $name:ident) => {
$(#[$attr])*
#[pin_project::pin_project]
#[derive(Debug)]
///
/// This structure implements a [`Stream`](futures_core::stream::Stream) interface and will read
/// compressed data from an underlying stream and emit a stream of uncompressed data.
pub struct $name<S: futures_core::stream::Stream<Item = std::io::Result<bytes::Bytes>>> {
#[pin]
inner: crate::stream::generic::Decoder<S, crate::codec::$name>,
pin_project_lite::pin_project! {
$(#[$attr])*
#[derive(Debug)]
///
/// This structure implements a [`Stream`](futures_core::stream::Stream) interface and will read
/// compressed data from an underlying stream and emit a stream of uncompressed data.
pub struct $name<S: futures_core::stream::Stream<Item = std::io::Result<bytes::Bytes>>> {
#[pin]
inner: crate::stream::generic::Decoder<S, crate::codec::$name>,
}
}

impl<S: futures_core::stream::Stream<Item = std::io::Result<bytes::Bytes>>> $name<S> {
Expand Down
19 changes: 10 additions & 9 deletions src/stream/macros/encoder.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
macro_rules! encoder {
($(#[$attr:meta])* $name:ident<$inner:ident> $({ $($constructor:tt)* })*) => {
$(#[$attr])*
#[pin_project::pin_project]
#[derive(Debug)]
///
/// This structure implements a [`Stream`](futures_core::stream::Stream) interface and will read
/// uncompressed data from an underlying stream and emit a stream of compressed data.
pub struct $name<$inner: futures_core::stream::Stream<Item = std::io::Result<bytes::Bytes>>> {
#[pin]
inner: crate::stream::Encoder<$inner, crate::codec::$name>,
pin_project_lite::pin_project! {
$(#[$attr])*
#[derive(Debug)]
///
/// This structure implements a [`Stream`](futures_core::stream::Stream) interface and will read
/// uncompressed data from an underlying stream and emit a stream of compressed data.
pub struct $name<$inner: futures_core::stream::Stream<Item = std::io::Result<bytes::Bytes>>> {
#[pin]
inner: crate::stream::Encoder<$inner, crate::codec::$name>,
}
}

impl<$inner: futures_core::stream::Stream<Item = std::io::Result<bytes::Bytes>>> $name<$inner> {
Expand Down
17 changes: 9 additions & 8 deletions src/write/buf_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use super::AsyncBufWrite;
use futures_core::ready;
use futures_io::{AsyncSeek, AsyncWrite, SeekFrom};
use pin_project::pin_project;
use pin_project_lite::pin_project;
use std::{
cmp::min,
fmt, io,
Expand All @@ -15,13 +15,14 @@ use std::{

const DEFAULT_BUF_SIZE: usize = 8192;

#[pin_project]
pub struct BufWriter<W> {
#[pin]
inner: W,
buf: Box<[u8]>,
written: usize,
buffered: usize,
pin_project! {
pub struct BufWriter<W> {
#[pin]
inner: W,
buf: Box<[u8]>,
written: usize,
buffered: usize,
}
}

impl<W: AsyncWrite> BufWriter<W> {
Expand Down
17 changes: 9 additions & 8 deletions src/write/generic/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
};
use futures_core::ready;
use futures_io::AsyncWrite;
use pin_project::pin_project;
use pin_project_lite::pin_project;

#[derive(Debug)]
enum State {
Expand All @@ -20,13 +20,14 @@ enum State {
Done,
}

#[pin_project]
#[derive(Debug)]
pub struct Decoder<W: AsyncWrite, D: Decode> {
#[pin]
writer: BufWriter<W>,
decoder: D,
state: State,
pin_project! {
#[derive(Debug)]
pub struct Decoder<W: AsyncWrite, D: Decode> {
#[pin]
writer: BufWriter<W>,
decoder: D,
state: State,
}
}

impl<W: AsyncWrite, D: Decode> Decoder<W, D> {
Expand Down
17 changes: 9 additions & 8 deletions src/write/generic/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
};
use futures_core::ready;
use futures_io::AsyncWrite;
use pin_project::pin_project;
use pin_project_lite::pin_project;

#[derive(Debug)]
enum State {
Expand All @@ -20,13 +20,14 @@ enum State {
Done,
}

#[pin_project]
#[derive(Debug)]
pub struct Encoder<W: AsyncWrite, E: Encode> {
#[pin]
writer: BufWriter<W>,
encoder: E,
state: State,
pin_project! {
#[derive(Debug)]
pub struct Encoder<W: AsyncWrite, E: Encode> {
#[pin]
writer: BufWriter<W>,
encoder: E,
state: State,
}
}

impl<W: AsyncWrite, E: Encode> Encoder<W, E> {
Expand Down
19 changes: 10 additions & 9 deletions src/write/macros/decoder.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
macro_rules! decoder {
($(#[$attr:meta])* $name:ident) => {
$(#[$attr])*
#[pin_project::pin_project]
#[derive(Debug)]
///
/// This structure implements an [`AsyncWrite`](futures_io::AsyncWrite) interface and will
/// take in compressed data and write it uncompressed to an underlying stream.
pub struct $name<W: futures_io::AsyncWrite> {
#[pin]
inner: crate::write::Decoder<W, crate::codec::$name>,
pin_project_lite::pin_project! {
$(#[$attr])*
#[derive(Debug)]
///
/// This structure implements an [`AsyncWrite`](futures_io::AsyncWrite) interface and will
/// take in compressed data and write it uncompressed to an underlying stream.
pub struct $name<W: futures_io::AsyncWrite> {
#[pin]
inner: crate::write::Decoder<W, crate::codec::$name>,
}
}

impl<W: futures_io::AsyncWrite> $name<W> {
Expand Down
19 changes: 10 additions & 9 deletions src/write/macros/encoder.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
macro_rules! encoder {
($(#[$attr:meta])* $name:ident<$inner:ident> $({ $($constructor:tt)* })*) => {
$(#[$attr])*
#[pin_project::pin_project]
#[derive(Debug)]
///
/// This structure implements an [`AsyncWrite`](futures_io::AsyncWrite) interface and will
/// take in uncompressed data and write it compressed to an underlying stream.
pub struct $name<$inner: futures_io::AsyncWrite> {
#[pin]
inner: crate::write::Encoder<$inner, crate::codec::$name>,
pin_project_lite::pin_project! {
$(#[$attr])*
#[derive(Debug)]
///
/// This structure implements an [`AsyncWrite`](futures_io::AsyncWrite) interface and will
/// take in uncompressed data and write it compressed to an underlying stream.
pub struct $name<$inner: futures_io::AsyncWrite> {
#[pin]
inner: crate::write::Encoder<$inner, crate::codec::$name>,
}
}

impl<$inner: futures_io::AsyncWrite> $name<$inner> {
Expand Down

0 comments on commit 434f69b

Please sign in to comment.