Skip to content

Commit 0f65592

Browse files
committed
Update to hyper 1.0
Fixes hjr3#24. This commit wraps up the hyper 1.0 update. Specific to this commit: - `test_read_timeout` error matching is rewritten to add the `hyper_util::client::legacy::Error` outermost level of abstraction - README is updated - passes all tests, clippy Bigger picture: - now uses hyper IO traits - no longer depends on tokio-io-timeout
1 parent 149fa51 commit 0f65592

File tree

4 files changed

+12
-27
lines changed

4 files changed

+12
-27
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@ There is a `TimeoutConnector` that implements the `hyper::Connect` trait. This c
1919
Hyper version compatibility:
2020

2121
* The `master` branch will track on going development for hyper.
22+
* The `0.5` release supports hyper 1.0.
2223
* The `0.4` release supports hyper 0.14.
2324
* The `0.3` release supports hyper 0.13.
2425
* The `0.2` release supports hyper 0.12.
2526
* The `0.1` release supports hyper 0.11.
2627

27-
Assuming you are using hyper 0.14, add this to your `Cargo.toml`:
28+
Assuming you are using hyper 1.0, add this to your `Cargo.toml`:
2829

2930
```toml
3031
[dependencies]
31-
hyper-timeout = "0.4"
32+
hyper-timeout = "0.5"
3233
```
3334

3435
See the [client example](./examples/client.rs) for a working example.

examples/client.rs

-2
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,3 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
4646

4747
Ok(())
4848
}
49-
50-

src/lib.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,13 @@ mod tests {
183183

184184
let res = client.get(url).await;
185185

186-
match res {
187-
Ok(_) => panic!("Expected a timeout"),
188-
Err(e) => {
189-
if let Some(io_e) = e.source().unwrap().downcast_ref::<io::Error>() {
190-
assert_eq!(io_e.kind(), io::ErrorKind::TimedOut);
191-
} else {
192-
panic!("Expected timeout error");
186+
if let Err(client_e) = res {
187+
if let Some(hyper_e) = client_e.source() {
188+
if let Some(io_e) = hyper_e.source().unwrap().downcast_ref::<io::Error>() {
189+
return assert_eq!(io_e.kind(), io::ErrorKind::TimedOut);
193190
}
194191
}
195192
}
193+
panic!("Expected timeout error");
196194
}
197195
}

src/stream.rs

+4-16
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use hyper_util::client::legacy::connect::{Connected, Connection};
1212
use pin_project_lite::pin_project;
1313
use std::future::Future;
1414
use std::io;
15-
use std::marker::PhantomPinned;
1615
use std::pin::Pin;
1716
use std::task::{ready, Context, Poll};
1817
use std::time::Duration;
@@ -500,8 +499,6 @@ pin_project! {
500499
struct ReadFut<'a, R: ?Sized> {
501500
reader: &'a mut R,
502501
buf: &'a mut [u8],
503-
#[pin]
504-
_pin: PhantomPinned,
505502
}
506503
}
507504

@@ -514,11 +511,7 @@ fn read<'a, R>(reader: &'a mut R, buf: &'a mut [u8]) -> ReadFut<'a, R>
514511
where
515512
R: Read + Unpin + ?Sized,
516513
{
517-
ReadFut {
518-
reader,
519-
buf,
520-
_pin: PhantomPinned,
521-
}
514+
ReadFut { reader, buf }
522515
}
523516

524517
impl<R> Future for ReadFut<'_, R>
@@ -551,8 +544,6 @@ pin_project! {
551544
struct WriteFut<'a, W: ?Sized> {
552545
writer: &'a mut W,
553546
buf: &'a [u8],
554-
#[pin]
555-
_pin: PhantomPinned,
556547
}
557548
}
558549

@@ -562,11 +553,7 @@ fn write<'a, W>(writer: &'a mut W, buf: &'a [u8]) -> WriteFut<'a, W>
562553
where
563554
W: Write + Unpin + ?Sized,
564555
{
565-
WriteFut {
566-
writer,
567-
buf,
568-
_pin: PhantomPinned,
569-
}
556+
WriteFut { writer, buf }
570557
}
571558

572559
impl<W> Future for WriteFut<'_, W>
@@ -694,7 +681,7 @@ mod test {
694681
reader.set_timeout(Some(Duration::from_millis(100)));
695682
pin!(reader);
696683

697-
let r = reader.read(&mut [0]).await;
684+
let r = reader.read(&mut [0, 1, 2]).await;
698685
assert_eq!(r.err().unwrap().kind(), io::ErrorKind::TimedOut);
699686
}
700687

@@ -757,3 +744,4 @@ mod test {
757744
}
758745
}
759746
}
747+

0 commit comments

Comments
 (0)