Skip to content

Commit 54c8670

Browse files
authored
refactor(common): move compat constructor to method (#3367)
1 parent 9420b73 commit 54c8670

File tree

8 files changed

+23
-22
lines changed

8 files changed

+23
-22
lines changed

src/common/io/compat.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ use std::task::{Context, Poll};
77
#[derive(Debug)]
88
pub(crate) struct Compat<T>(pub(crate) T);
99

10-
pub(crate) fn compat<T>(io: T) -> Compat<T> {
11-
Compat(io)
12-
}
13-
1410
impl<T> Compat<T> {
11+
pub(crate) fn new(io: T) -> Self {
12+
Compat(io)
13+
}
14+
1515
fn p(self: Pin<&mut Self>) -> Pin<&mut T> {
1616
// SAFETY: The simplest of projections. This is just
1717
// a wrapper, we don't do anything that would undo the projection.

src/common/io/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ mod compat;
33
mod rewind;
44

55
#[cfg(all(any(feature = "client", feature = "server"), feature = "http2"))]
6-
pub(crate) use self::compat::{compat, Compat};
6+
pub(crate) use self::compat::Compat;
77
pub(crate) use self::rewind::Rewind;

src/common/io/rewind.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ where
108108

109109
#[cfg(test)]
110110
mod tests {
111-
use super::super::compat;
111+
use super::super::Compat;
112112
use super::Rewind;
113113
use bytes::Bytes;
114114
use tokio::io::AsyncReadExt;
@@ -120,7 +120,7 @@ mod tests {
120120

121121
let mock = tokio_test::io::Builder::new().read(&underlying).build();
122122

123-
let mut stream = compat(Rewind::new(compat(mock)));
123+
let mut stream = Compat::new(Rewind::new(Compat::new(mock)));
124124

125125
// Read off some bytes, ensure we filled o1
126126
let mut buf = [0; 2];
@@ -143,7 +143,7 @@ mod tests {
143143

144144
let mock = tokio_test::io::Builder::new().read(&underlying).build();
145145

146-
let mut stream = compat(Rewind::new(compat(mock)));
146+
let mut stream = Compat::new(Rewind::new(Compat::new(mock)));
147147

148148
let mut buf = [0; 5];
149149
stream.read_exact(&mut buf).await.expect("read1");

src/proto/h1/decode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ mod tests {
627627
async fn read_async(mut decoder: Decoder, content: &[u8], block_at: usize) -> String {
628628
let mut outs = Vec::new();
629629

630-
let mut ins = crate::common::io::compat(if block_at == 0 {
630+
let mut ins = crate::common::io::Compat::new(if block_at == 0 {
631631
tokio_test::io::Builder::new()
632632
.wait(Duration::from_millis(10))
633633
.read(content)

src/proto/h1/dispatch.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ cfg_client! {
668668
#[cfg(test)]
669669
mod tests {
670670
use super::*;
671-
use crate::common::io::compat;
671+
use crate::common::io::Compat;
672672
use crate::proto::h1::ClientTransaction;
673673
use std::time::Duration;
674674

@@ -682,7 +682,7 @@ mod tests {
682682
// Block at 0 for now, but we will release this response before
683683
// the request is ready to write later...
684684
let (mut tx, rx) = crate::client::dispatch::channel();
685-
let conn = Conn::<_, bytes::Bytes, ClientTransaction>::new(compat(io));
685+
let conn = Conn::<_, bytes::Bytes, ClientTransaction>::new(Compat::new(io));
686686
let mut dispatcher = Dispatcher::new(Client::new(rx), conn);
687687

688688
// First poll is needed to allow tx to send...
@@ -719,7 +719,7 @@ mod tests {
719719
.build_with_handle();
720720

721721
let (mut tx, rx) = crate::client::dispatch::channel();
722-
let mut conn = Conn::<_, bytes::Bytes, ClientTransaction>::new(compat(io));
722+
let mut conn = Conn::<_, bytes::Bytes, ClientTransaction>::new(Compat::new(io));
723723
conn.set_write_strategy_queue();
724724

725725
let dispatcher = Dispatcher::new(Client::new(rx), conn);
@@ -750,7 +750,7 @@ mod tests {
750750
.build();
751751

752752
let (mut tx, rx) = crate::client::dispatch::channel();
753-
let conn = Conn::<_, bytes::Bytes, ClientTransaction>::new(compat(io));
753+
let conn = Conn::<_, bytes::Bytes, ClientTransaction>::new(Compat::new(io));
754754
let mut dispatcher = tokio_test::task::spawn(Dispatcher::new(Client::new(rx), conn));
755755

756756
// First poll is needed to allow tx to send...

src/proto/h1/io.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ enum WriteStrategy {
659659

660660
#[cfg(test)]
661661
mod tests {
662-
use crate::common::io::compat;
662+
use crate::common::io::Compat;
663663
use crate::common::time::Time;
664664

665665
use super::*;
@@ -715,7 +715,7 @@ mod tests {
715715
.wait(Duration::from_secs(1))
716716
.build();
717717

718-
let mut buffered = Buffered::<_, Cursor<Vec<u8>>>::new(compat(mock));
718+
let mut buffered = Buffered::<_, Cursor<Vec<u8>>>::new(Compat::new(mock));
719719

720720
// We expect a `parse` to be not ready, and so can't await it directly.
721721
// Rather, this `poll_fn` will wrap the `Poll` result.
@@ -860,7 +860,7 @@ mod tests {
860860
#[cfg(debug_assertions)] // needs to trigger a debug_assert
861861
fn write_buf_requires_non_empty_bufs() {
862862
let mock = Mock::new().build();
863-
let mut buffered = Buffered::<_, Cursor<Vec<u8>>>::new(compat(mock));
863+
let mut buffered = Buffered::<_, Cursor<Vec<u8>>>::new(Compat::new(mock));
864864

865865
buffered.buffer(Cursor::new(Vec::new()));
866866
}
@@ -895,7 +895,7 @@ mod tests {
895895

896896
let mock = Mock::new().write(b"hello world, it's hyper!").build();
897897

898-
let mut buffered = Buffered::<_, Cursor<Vec<u8>>>::new(compat(mock));
898+
let mut buffered = Buffered::<_, Cursor<Vec<u8>>>::new(Compat::new(mock));
899899
buffered.write_buf.set_strategy(WriteStrategy::Flatten);
900900

901901
buffered.headers_buf().extend(b"hello ");
@@ -954,7 +954,7 @@ mod tests {
954954
.write(b"hyper!")
955955
.build();
956956

957-
let mut buffered = Buffered::<_, Cursor<Vec<u8>>>::new(compat(mock));
957+
let mut buffered = Buffered::<_, Cursor<Vec<u8>>>::new(Compat::new(mock));
958958
buffered.write_buf.set_strategy(WriteStrategy::Queue);
959959

960960
// we have 4 buffers, and vec IO disabled, but explicitly said

src/proto/h2/client.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ where
122122
B::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
123123
{
124124
let (h2_tx, mut conn) = new_builder(config)
125-
.handshake::<_, SendBuf<B::Data>>(crate::common::io::compat(io))
125+
.handshake::<_, SendBuf<B::Data>>(Compat::new(io))
126126
.await
127127
.map_err(crate::Error::new_h2)?;
128128

src/proto/h2/server.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use pin_project_lite::pin_project;
1414
use super::{ping, PipeToSendStream, SendBuf};
1515
use crate::body::{Body, Incoming as IncomingBody};
1616
use crate::common::date;
17+
use crate::common::io::Compat;
1718
use crate::common::time::Time;
1819
use crate::ext::Protocol;
1920
use crate::headers;
@@ -90,7 +91,7 @@ where
9091
{
9192
Handshaking {
9293
ping_config: ping::Config,
93-
hs: Handshake<crate::common::io::Compat<T>, SendBuf<B::Data>>,
94+
hs: Handshake<Compat<T>, SendBuf<B::Data>>,
9495
},
9596
Serving(Serving<T, B>),
9697
Closed,
@@ -101,7 +102,7 @@ where
101102
B: Body,
102103
{
103104
ping: Option<(ping::Recorder, ping::Ponger)>,
104-
conn: Connection<crate::common::io::Compat<T>, SendBuf<B::Data>>,
105+
conn: Connection<Compat<T>, SendBuf<B::Data>>,
105106
closing: Option<crate::Error>,
106107
}
107108

@@ -133,7 +134,7 @@ where
133134
if config.enable_connect_protocol {
134135
builder.enable_connect_protocol();
135136
}
136-
let handshake = builder.handshake(crate::common::io::compat(io));
137+
let handshake = builder.handshake(Compat::new(io));
137138

138139
let bdp = if config.adaptive_window {
139140
Some(config.initial_stream_window_size)

0 commit comments

Comments
 (0)