Skip to content

Commit bb68fd1

Browse files
committed
refactor: make it visually clear that inner param is shared
1 parent 24556b1 commit bb68fd1

File tree

5 files changed

+51
-51
lines changed

5 files changed

+51
-51
lines changed

src/futures/bufread/macros/decoder.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
macro_rules! decoder {
2-
($(#[$attr:meta])* $name:ident $({ $($inherent_methods:tt)* })*) => {
2+
($(#[$attr:meta])* $name:ident<$inner: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<R> {
9+
pub struct $name<$inner> {
1010
#[pin]
11-
inner: crate::futures::bufread::Decoder<R, crate::codec::$name>,
11+
inner: crate::futures::bufread::Decoder<$inner, crate::codec::$name>,
1212
}
1313
}
1414

15-
impl<R: futures_io::AsyncBufRead> $name<R> {
15+
impl<$inner: futures_io::AsyncBufRead> $name<$inner> {
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: R) -> $name<R> {
18+
pub fn new(read: $inner) -> $name<$inner> {
1919
$name {
2020
inner: crate::futures::bufread::Decoder::new(read, crate::codec::$name::new()),
2121
}
@@ -31,7 +31,7 @@ macro_rules! decoder {
3131
}
3232

3333
/// Acquires a reference to the underlying reader that this decoder is wrapping.
34-
pub fn get_ref(&self) -> &R {
34+
pub fn get_ref(&self) -> &$inner {
3535
self.inner.get_ref()
3636
}
3737

@@ -40,7 +40,7 @@ macro_rules! decoder {
4040
///
4141
/// Note that care must be taken to avoid tampering with the state of the reader which
4242
/// may otherwise confuse this decoder.
43-
pub fn get_mut(&mut self) -> &mut R {
43+
pub fn get_mut(&mut self) -> &mut $inner {
4444
self.inner.get_mut()
4545
}
4646

@@ -49,20 +49,20 @@ macro_rules! decoder {
4949
///
5050
/// Note that care must be taken to avoid tampering with the state of the reader which
5151
/// may otherwise confuse this decoder.
52-
pub fn get_pin_mut(self: std::pin::Pin<&mut Self>) -> std::pin::Pin<&mut R> {
52+
pub fn get_pin_mut(self: std::pin::Pin<&mut Self>) -> std::pin::Pin<&mut $inner> {
5353
self.project().inner.get_pin_mut()
5454
}
5555

5656
/// Consumes this decoder returning the underlying reader.
5757
///
5858
/// Note that this may discard internal state of this decoder, so care should be taken
5959
/// to avoid losing resources when this is called.
60-
pub fn into_inner(self) -> R {
60+
pub fn into_inner(self) -> $inner {
6161
self.inner.into_inner()
6262
}
6363
}
6464

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

src/futures/write/macros/decoder.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
macro_rules! decoder {
2-
($(#[$attr:meta])* $name:ident $({ $($inherent_methods:tt)* })*) => {
2+
($(#[$attr:meta])* $name:ident<$inner: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<W> {
9+
pub struct $name<$inner> {
1010
#[pin]
11-
inner: crate::futures::write::Decoder<W, crate::codec::$name>,
11+
inner: crate::futures::write::Decoder<$inner, crate::codec::$name>,
1212
}
1313
}
1414

15-
impl<W: futures_io::AsyncWrite> $name<W> {
15+
impl<$inner: futures_io::AsyncWrite> $name<$inner> {
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: W) -> $name<W> {
18+
pub fn new(read: $inner) -> $name<$inner> {
1919
$name {
2020
inner: crate::futures::write::Decoder::new(read, crate::codec::$name::new()),
2121
}
@@ -24,7 +24,7 @@ macro_rules! decoder {
2424
$($($inherent_methods)*)*
2525

2626
/// Acquires a reference to the underlying reader that this decoder is wrapping.
27-
pub fn get_ref(&self) -> &W {
27+
pub fn get_ref(&self) -> &$inner {
2828
self.inner.get_ref()
2929
}
3030

@@ -33,7 +33,7 @@ macro_rules! decoder {
3333
///
3434
/// Note that care must be taken to avoid tampering with the state of the reader which
3535
/// may otherwise confuse this decoder.
36-
pub fn get_mut(&mut self) -> &mut W {
36+
pub fn get_mut(&mut self) -> &mut $inner {
3737
self.inner.get_mut()
3838
}
3939

@@ -42,20 +42,20 @@ macro_rules! decoder {
4242
///
4343
/// Note that care must be taken to avoid tampering with the state of the reader which
4444
/// may otherwise confuse this decoder.
45-
pub fn get_pin_mut(self: std::pin::Pin<&mut Self>) -> std::pin::Pin<&mut W> {
45+
pub fn get_pin_mut(self: std::pin::Pin<&mut Self>) -> std::pin::Pin<&mut $inner> {
4646
self.project().inner.get_pin_mut()
4747
}
4848

4949
/// Consumes this decoder returning the underlying reader.
5050
///
5151
/// Note that this may discard internal state of this decoder, so care should be taken
5252
/// to avoid losing resources when this is called.
53-
pub fn into_inner(self) -> W {
53+
pub fn into_inner(self) -> $inner {
5454
self.inner.into_inner()
5555
}
5656
}
5757

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

src/macros.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
macro_rules! algos {
2-
(@algo $algo:ident [$algo_s:expr] $decoder:ident $encoder:ident<$inner:ident>
2+
(@algo $algo:ident [$algo_s:expr] $decoder:ident $encoder:ident <$inner:ident>
33
{ @enc $($encoder_methods:tt)* }
44
{ @dec $($decoder_methods:tt)* }
55
) => {
66
#[cfg(feature = $algo_s)]
77
decoder! {
88
#[doc = concat!("A ", $algo_s, " decoder, or decompressor")]
99
#[cfg(feature = $algo_s)]
10-
$decoder
10+
$decoder<$inner>
1111

1212
{ $($decoder_methods)* }
1313
}
@@ -26,8 +26,8 @@ macro_rules! algos {
2626
}
2727
};
2828

29-
($($mod:ident)::+<$inner:ident>) => {
30-
algos!(@algo brotli ["brotli"] BrotliDecoder BrotliEncoder<$inner>
29+
($($mod:ident)::+ <$inner:ident>) => {
30+
algos!(@algo brotli ["brotli"] BrotliDecoder BrotliEncoder <$inner>
3131
{ @enc
3232
pub fn with_quality(inner: $inner, level: crate::Level) -> Self {
3333
let params = brotli::enc::backward_references::BrotliEncoderParams::default();
@@ -42,7 +42,7 @@ macro_rules! algos {
4242
{ @dec }
4343
);
4444

45-
algos!(@algo bzip2 ["bzip2"] BzDecoder BzEncoder<$inner>
45+
algos!(@algo bzip2 ["bzip2"] BzDecoder BzEncoder <$inner>
4646
{ @enc
4747

4848
pub fn with_quality(inner: $inner, level: crate::Level) -> Self {
@@ -57,7 +57,7 @@ macro_rules! algos {
5757
{ @dec }
5858
);
5959

60-
algos!(@algo deflate ["deflate"] DeflateDecoder DeflateEncoder<$inner>
60+
algos!(@algo deflate ["deflate"] DeflateDecoder DeflateEncoder <$inner>
6161
{ @enc
6262
pub fn with_quality(inner: $inner, level: crate::Level) -> Self {
6363
Self {
@@ -71,7 +71,7 @@ macro_rules! algos {
7171
{ @dec }
7272
);
7373

74-
algos!(@algo gzip ["gzip"] GzipDecoder GzipEncoder<$inner>
74+
algos!(@algo gzip ["gzip"] GzipDecoder GzipEncoder <$inner>
7575
{ @enc
7676

7777
pub fn with_quality(inner: $inner, level: crate::Level) -> Self {
@@ -86,7 +86,7 @@ macro_rules! algos {
8686
{ @dec }
8787
);
8888

89-
algos!(@algo zlib ["zlib"] ZlibDecoder ZlibEncoder<$inner>
89+
algos!(@algo zlib ["zlib"] ZlibDecoder ZlibEncoder <$inner>
9090
{ @enc
9191
pub fn with_quality(inner: $inner, level: crate::Level) -> Self {
9292
Self {
@@ -100,7 +100,7 @@ macro_rules! algos {
100100
{ @dec }
101101
);
102102

103-
algos!(@algo zstd ["zstd"] ZstdDecoder ZstdEncoder<$inner>
103+
algos!(@algo zstd ["zstd"] ZstdDecoder ZstdEncoder <$inner>
104104
{ @enc
105105

106106
pub fn with_quality(inner: $inner, level: crate::Level) -> Self {
@@ -175,7 +175,7 @@ macro_rules! algos {
175175
}
176176
);
177177

178-
algos!(@algo xz ["xz"] XzDecoder XzEncoder<$inner>
178+
algos!(@algo xz ["xz"] XzDecoder XzEncoder <$inner>
179179
{ @enc
180180

181181
pub fn with_quality(inner: $inner, level: crate::Level) -> Self {
@@ -190,7 +190,7 @@ macro_rules! algos {
190190
{ @dec }
191191
);
192192

193-
algos!(@algo lzma ["lzma"] LzmaDecoder LzmaEncoder<$inner>
193+
algos!(@algo lzma ["lzma"] LzmaDecoder LzmaEncoder <$inner>
194194
{ @enc
195195

196196
pub fn with_quality(inner: $inner, level: crate::Level) -> Self {

src/tokio/bufread/macros/decoder.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
macro_rules! decoder {
2-
($(#[$attr:meta])* $name:ident $({ $($inherent_methods:tt)* })*) => {
2+
($(#[$attr:meta])* $name:ident<$inner:ident> $({ $($inherent_methods:tt)* })*) => {
33
pin_project_lite::pin_project! {
44
$(#[$attr])*
55
///
66
/// This structure implements an [`AsyncRead`](tokio::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<R> {
9+
pub struct $name<$inner> {
1010
#[pin]
11-
inner: crate::tokio::bufread::Decoder<R, crate::codec::$name>,
11+
inner: crate::tokio::bufread::Decoder<$inner, crate::codec::$name>,
1212
}
1313
}
1414

15-
impl<R: tokio::io::AsyncBufRead> $name<R> {
15+
impl<$inner: tokio::io::AsyncBufRead> $name<$inner> {
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: R) -> $name<R> {
18+
pub fn new(read: $inner) -> $name<$inner> {
1919
$name {
2020
inner: crate::tokio::bufread::Decoder::new(read, crate::codec::$name::new()),
2121
}
@@ -31,7 +31,7 @@ macro_rules! decoder {
3131
}
3232

3333
/// Acquires a reference to the underlying reader that this decoder is wrapping.
34-
pub fn get_ref(&self) -> &R {
34+
pub fn get_ref(&self) -> &$inner {
3535
self.inner.get_ref()
3636
}
3737

@@ -40,7 +40,7 @@ macro_rules! decoder {
4040
///
4141
/// Note that care must be taken to avoid tampering with the state of the reader which
4242
/// may otherwise confuse this decoder.
43-
pub fn get_mut(&mut self) -> &mut R {
43+
pub fn get_mut(&mut self) -> &mut $inner {
4444
self.inner.get_mut()
4545
}
4646

@@ -49,20 +49,20 @@ macro_rules! decoder {
4949
///
5050
/// Note that care must be taken to avoid tampering with the state of the reader which
5151
/// may otherwise confuse this decoder.
52-
pub fn get_pin_mut(self: std::pin::Pin<&mut Self>) -> std::pin::Pin<&mut R> {
52+
pub fn get_pin_mut(self: std::pin::Pin<&mut Self>) -> std::pin::Pin<&mut $inner> {
5353
self.project().inner.get_pin_mut()
5454
}
5555

5656
/// Consumes this decoder returning the underlying reader.
5757
///
5858
/// Note that this may discard internal state of this decoder, so care should be taken
5959
/// to avoid losing resources when this is called.
60-
pub fn into_inner(self) -> R {
60+
pub fn into_inner(self) -> $inner {
6161
self.inner.into_inner()
6262
}
6363
}
6464

65-
impl<R: tokio::io::AsyncBufRead> tokio::io::AsyncRead for $name<R> {
65+
impl<$inner: tokio::io::AsyncBufRead> tokio::io::AsyncRead for $name<$inner> {
6666
fn poll_read(
6767
self: std::pin::Pin<&mut Self>,
6868
cx: &mut std::task::Context<'_>,

src/tokio/write/macros/decoder.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
macro_rules! decoder {
2-
($(#[$attr:meta])* $name:ident $({ $($inherent_methods:tt)* })*) => {
2+
($(#[$attr:meta])* $name:ident<$inner:ident> $({ $($inherent_methods:tt)* })*) => {
33
pin_project_lite::pin_project! {
44
$(#[$attr])*
55
///
66
/// This structure implements an [`AsyncWrite`](tokio::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<W> {
9+
pub struct $name<$inner> {
1010
#[pin]
11-
inner: crate::tokio::write::Decoder<W, crate::codec::$name>,
11+
inner: crate::tokio::write::Decoder<$inner, crate::codec::$name>,
1212
}
1313
}
1414

15-
impl<W: tokio::io::AsyncWrite> $name<W> {
15+
impl<$inner: tokio::io::AsyncWrite> $name<$inner> {
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: W) -> $name<W> {
18+
pub fn new(read: $inner) -> $name<$inner> {
1919
$name {
2020
inner: crate::tokio::write::Decoder::new(read, crate::codec::$name::new()),
2121
}
@@ -24,7 +24,7 @@ macro_rules! decoder {
2424
$($($inherent_methods)*)*
2525

2626
/// Acquires a reference to the underlying reader that this decoder is wrapping.
27-
pub fn get_ref(&self) -> &W {
27+
pub fn get_ref(&self) -> &$inner {
2828
self.inner.get_ref()
2929
}
3030

@@ -33,7 +33,7 @@ macro_rules! decoder {
3333
///
3434
/// Note that care must be taken to avoid tampering with the state of the reader which
3535
/// may otherwise confuse this decoder.
36-
pub fn get_mut(&mut self) -> &mut W {
36+
pub fn get_mut(&mut self) -> &mut $inner {
3737
self.inner.get_mut()
3838
}
3939

@@ -42,20 +42,20 @@ macro_rules! decoder {
4242
///
4343
/// Note that care must be taken to avoid tampering with the state of the reader which
4444
/// may otherwise confuse this decoder.
45-
pub fn get_pin_mut(self: std::pin::Pin<&mut Self>) -> std::pin::Pin<&mut W> {
45+
pub fn get_pin_mut(self: std::pin::Pin<&mut Self>) -> std::pin::Pin<&mut $inner> {
4646
self.project().inner.get_pin_mut()
4747
}
4848

4949
/// Consumes this decoder returning the underlying reader.
5050
///
5151
/// Note that this may discard internal state of this decoder, so care should be taken
5252
/// to avoid losing resources when this is called.
53-
pub fn into_inner(self) -> W {
53+
pub fn into_inner(self) -> $inner {
5454
self.inner.into_inner()
5555
}
5656
}
5757

58-
impl<W: tokio::io::AsyncWrite> tokio::io::AsyncWrite for $name<W> {
58+
impl<$inner: tokio::io::AsyncWrite> tokio::io::AsyncWrite for $name<$inner> {
5959
fn poll_write(
6060
self: std::pin::Pin<&mut Self>,
6161
cx: &mut std::task::Context<'_>,

0 commit comments

Comments
 (0)