Skip to content

Commit 044ee63

Browse files
committed
refactor: simplify PR
1 parent 0d28ed5 commit 044ee63

File tree

13 files changed

+153
-125
lines changed

13 files changed

+153
-125
lines changed

src/futures/bufread/macros/decoder.rs

+11-13
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
11
macro_rules! decoder {
2-
($(#[$attr:meta])* $name:ident<$inner:ident> $({ $($constructor:tt)* })*) => {
2+
($(#[$attr:meta])* $name:ident $({ $($inherent_methods:tt)* })*) => {
33
pin_project_lite::pin_project! {
44
$(#[$attr])*
55
///
66
/// This structure implements an [`AsyncRead`](futures_io::AsyncRead) interface and will
77
/// read compressed data from an underlying stream and emit a stream of uncompressed data.
88
#[derive(Debug)]
9-
pub struct $name<$inner> {
9+
pub struct $name<R> {
1010
#[pin]
11-
inner: crate::futures::bufread::Decoder<$inner, crate::codec::$name>,
11+
inner: crate::futures::bufread::Decoder<R, crate::codec::$name>,
1212
}
1313
}
1414

15-
impl<$inner: futures_io::AsyncBufRead> $name<$inner> {
15+
impl<R: futures_io::AsyncBufRead> $name<R> {
1616
/// Creates a new decoder which will read compressed data from the given stream and
1717
/// emit a uncompressed stream.
18-
pub fn new(read: $inner) -> $name<$inner> {
18+
pub fn new(read: R) -> $name<R> {
1919
$name {
2020
inner: crate::futures::bufread::Decoder::new(read, crate::codec::$name::new()),
2121
}
2222
}
2323

24-
$(
25-
$($constructor)*
26-
)*
24+
$($($inherent_methods)*)*
2725

2826
/// Configure multi-member/frame decoding, if enabled this will reset the decoder state
2927
/// when reaching the end of a compressed member/frame and expect either EOF or another
@@ -33,7 +31,7 @@ macro_rules! decoder {
3331
}
3432

3533
/// Acquires a reference to the underlying reader that this decoder is wrapping.
36-
pub fn get_ref(&self) -> &$inner {
34+
pub fn get_ref(&self) -> &R {
3735
self.inner.get_ref()
3836
}
3937

@@ -42,7 +40,7 @@ macro_rules! decoder {
4240
///
4341
/// Note that care must be taken to avoid tampering with the state of the reader which
4442
/// may otherwise confuse this decoder.
45-
pub fn get_mut(&mut self) -> &mut $inner {
43+
pub fn get_mut(&mut self) -> &mut R {
4644
self.inner.get_mut()
4745
}
4846

@@ -51,20 +49,20 @@ macro_rules! decoder {
5149
///
5250
/// Note that care must be taken to avoid tampering with the state of the reader which
5351
/// may otherwise confuse this decoder.
54-
pub fn get_pin_mut(self: std::pin::Pin<&mut Self>) -> std::pin::Pin<&mut $inner> {
52+
pub fn get_pin_mut(self: std::pin::Pin<&mut Self>) -> std::pin::Pin<&mut R> {
5553
self.project().inner.get_pin_mut()
5654
}
5755

5856
/// Consumes this decoder returning the underlying reader.
5957
///
6058
/// Note that this may discard internal state of this decoder, so care should be taken
6159
/// to avoid losing resources when this is called.
62-
pub fn into_inner(self) -> $inner {
60+
pub fn into_inner(self) -> R {
6361
self.inner.into_inner()
6462
}
6563
}
6664

67-
impl<$inner: futures_io::AsyncBufRead> futures_io::AsyncRead for $name<$inner> {
65+
impl<R: futures_io::AsyncBufRead> futures_io::AsyncRead for $name<R> {
6866
fn poll_read(
6967
self: std::pin::Pin<&mut Self>,
7068
cx: &mut std::task::Context<'_>,

src/futures/bufread/macros/encoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
macro_rules! encoder {
2-
($(#[$attr:meta])* $name:ident<$inner:ident> $({ $($constructor:tt)* })*) => {
2+
($(#[$attr:meta])* $name:ident<$inner:ident> $({ $($inherent_methods:tt)* })*) => {
33
pin_project_lite::pin_project! {
44
$(#[$attr])*
55
///
@@ -17,7 +17,7 @@ macro_rules! encoder {
1717
/// Creates a new encoder which will read uncompressed data from the given stream
1818
/// and emit a compressed stream.
1919
///
20-
$($constructor)*
20+
$($inherent_methods)*
2121
)*
2222

2323
/// Acquires a reference to the underlying reader that this encoder is wrapping.

src/futures/bufread/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ mod generic;
77

88
pub(crate) use generic::{Decoder, Encoder};
99

10-
algos!(futures::bufread<R1, R2>);
10+
algos!(futures::bufread<R>);

src/futures/write/macros/decoder.rs

+11-13
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,30 @@
11
macro_rules! decoder {
2-
($(#[$attr:meta])* $name:ident<$inner:ident> $({ $($constructor:tt)* })*) => {
2+
($(#[$attr:meta])* $name:ident $({ $($inherent_methods:tt)* })*) => {
33
pin_project_lite::pin_project! {
44
$(#[$attr])*
55
///
66
/// This structure implements an [`AsyncWrite`](futures_io::AsyncWrite) interface and will
77
/// take in compressed data and write it uncompressed to an underlying stream.
88
#[derive(Debug)]
9-
pub struct $name<$inner> {
9+
pub struct $name<W> {
1010
#[pin]
11-
inner: crate::futures::write::Decoder<$inner, crate::codec::$name>,
11+
inner: crate::futures::write::Decoder<W, crate::codec::$name>,
1212
}
1313
}
1414

15-
impl<$inner: futures_io::AsyncWrite> $name<$inner> {
15+
impl<W: futures_io::AsyncWrite> $name<W> {
1616
/// Creates a new decoder which will take in compressed data and write it uncompressed
1717
/// to the given stream.
18-
pub fn new(read: $inner) -> $name<$inner> {
18+
pub fn new(read: W) -> $name<W> {
1919
$name {
2020
inner: crate::futures::write::Decoder::new(read, crate::codec::$name::new()),
2121
}
2222
}
2323

24-
$(
25-
$($constructor)*
26-
)*
24+
$($($inherent_methods)*)*
2725

2826
/// Acquires a reference to the underlying reader that this decoder is wrapping.
29-
pub fn get_ref(&self) -> &$inner {
27+
pub fn get_ref(&self) -> &W {
3028
self.inner.get_ref()
3129
}
3230

@@ -35,7 +33,7 @@ macro_rules! decoder {
3533
///
3634
/// Note that care must be taken to avoid tampering with the state of the reader which
3735
/// may otherwise confuse this decoder.
38-
pub fn get_mut(&mut self) -> &mut $inner {
36+
pub fn get_mut(&mut self) -> &mut W {
3937
self.inner.get_mut()
4038
}
4139

@@ -44,20 +42,20 @@ macro_rules! decoder {
4442
///
4543
/// Note that care must be taken to avoid tampering with the state of the reader which
4644
/// may otherwise confuse this decoder.
47-
pub fn get_pin_mut(self: std::pin::Pin<&mut Self>) -> std::pin::Pin<&mut $inner> {
45+
pub fn get_pin_mut(self: std::pin::Pin<&mut Self>) -> std::pin::Pin<&mut W> {
4846
self.project().inner.get_pin_mut()
4947
}
5048

5149
/// Consumes this decoder returning the underlying reader.
5250
///
5351
/// Note that this may discard internal state of this decoder, so care should be taken
5452
/// to avoid losing resources when this is called.
55-
pub fn into_inner(self) -> $inner {
53+
pub fn into_inner(self) -> W {
5654
self.inner.into_inner()
5755
}
5856
}
5957

60-
impl<$inner: futures_io::AsyncWrite> futures_io::AsyncWrite for $name<$inner> {
58+
impl<W: futures_io::AsyncWrite> futures_io::AsyncWrite for $name<W> {
6159
fn poll_write(
6260
self: std::pin::Pin<&mut Self>,
6361
cx: &mut std::task::Context<'_>,

src/futures/write/macros/encoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
macro_rules! encoder {
2-
($(#[$attr:meta])* $name:ident<$inner:ident> $({ $($constructor:tt)* })*) => {
2+
($(#[$attr:meta])* $name:ident<$inner:ident> $({ $($inherent_methods:tt)* })*) => {
33
pin_project_lite::pin_project! {
44
$(#[$attr])*
55
///
@@ -17,7 +17,7 @@ macro_rules! encoder {
1717
/// Creates a new encoder which will take in uncompressed data and write it
1818
/// compressed to the given stream.
1919
///
20-
$($constructor)*
20+
$($inherent_methods)*
2121
)*
2222

2323
/// Acquires a reference to the underlying writer that this encoder is wrapping.

src/futures/write/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ use self::{
1414
generic::{Decoder, Encoder},
1515
};
1616

17-
algos!(futures::write<W1, W2>);
17+
algos!(futures::write<W>);

0 commit comments

Comments
 (0)