Skip to content

Commit f1f0ffc

Browse files
committed
Replace async-std with smol crates
It would be nice to be able to use this in environments where I use smol. However this crate imports the async-std crate for I/O. This commit partially replaces async-std with the equivalent combinators from futures-lite and async-io, two smol crates that async-std depends on anyways. The task spawn is still left in, as replacing it will be controversial. Signed-off-by: John Nunley <dev@notgull.net>
1 parent 882fa23 commit f1f0ffc

File tree

13 files changed

+41
-28
lines changed

13 files changed

+41
-28
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ log = "0.4.11"
2626
pin-project = "1.0.2"
2727
async-channel = "1.5.1"
2828
async-dup = "1.2.2"
29+
futures-lite = "1.13.0"
30+
async-io = "1.13.0"
2931

3032
[dev-dependencies]
3133
pretty_assertions = "0.6.1"

src/body_encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::io;
22
use std::pin::Pin;
33
use std::task::{Context, Poll};
44

5-
use async_std::io::Read;
5+
use futures_lite::io::AsyncRead as Read;
66
use http_types::Body;
77
use pin_project::pin_project;
88

src/chunked/decoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use std::future::Future;
33
use std::pin::Pin;
44
use std::task::{Context, Poll};
55

6-
use async_std::io::{self, Read};
7-
use futures_core::ready;
6+
use futures_lite::io::{self, AsyncRead as Read};
7+
use futures_lite::ready;
88
use http_types::trailers::{Sender, Trailers};
99

1010
/// Decodes a chunked body according to

src/chunked/encoder.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use std::pin::Pin;
2+
use std::task::{Context, Poll};
23

3-
use async_std::io;
4-
use async_std::io::prelude::*;
5-
use async_std::task::{Context, Poll};
6-
use futures_core::ready;
4+
use futures_lite::io::AsyncRead as Read;
5+
use futures_lite::{io, ready};
76

87
/// An encoder for chunked encoding.
98
#[derive(Debug)]

src/client/decode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use async_std::io::{BufReader, Read};
2-
use async_std::prelude::*;
1+
use futures_lite::io::{AsyncRead as Read, BufReader};
2+
use futures_lite::prelude::*;
33
use http_types::{ensure, ensure_eq, format_err};
44
use http_types::{
55
headers::{CONTENT_LENGTH, DATE, TRANSFER_ENCODING},

src/client/encode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::io::Write;
22
use std::pin::Pin;
3+
use std::task::{Context, Poll};
34

4-
use async_std::io::{self, Cursor, Read};
5-
use async_std::task::{Context, Poll};
5+
use futures_lite::io::{self, AsyncRead as Read, Cursor};
66
use http_types::headers::{CONTENT_LENGTH, HOST, TRANSFER_ENCODING};
77
use http_types::{Method, Request};
88

src/client/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Process HTTP connections on the client.
22
3-
use async_std::io::{self, Read, Write};
3+
use futures_lite::io::{self, AsyncRead as Read, AsyncWrite as Write};
44
use http_types::{Request, Response};
55

66
mod decode;

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ mod read_notifier;
112112
pub mod client;
113113
pub mod server;
114114

115-
use async_std::io::Cursor;
116115
use body_encoder::BodyEncoder;
117116
pub use client::connect;
117+
use futures_lite::io::Cursor;
118118
pub use server::{accept, accept_with_opts, ServerOptions};
119119

120120
#[derive(Debug)]

src/read_notifier.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::pin::Pin;
33
use std::task::{Context, Poll};
44

55
use async_channel::Sender;
6-
use async_std::io::{self, BufRead, Read};
6+
use futures_lite::io::{self, AsyncBufRead as BufRead, AsyncRead as Read};
77

88
/// ReadNotifier forwards [`async_std::io::Read`] and
99
/// [`async_std::io::BufRead`] to an inner reader. When the

src/server/body_reader.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
use crate::chunked::ChunkedDecoder;
22
use async_dup::{Arc, Mutex};
3-
use async_std::io::{BufReader, Read, Take};
4-
use async_std::task::{Context, Poll};
5-
use std::{fmt::Debug, io, pin::Pin};
3+
use futures_lite::io::{AsyncRead as Read, BufReader, Take};
4+
use std::{
5+
fmt::Debug,
6+
io,
7+
pin::Pin,
8+
task::{Context, Poll},
9+
};
610

711
pub enum BodyReader<IO: Read + Unpin> {
812
Chunked(Arc<Mutex<ChunkedDecoder<BufReader<IO>>>>),

0 commit comments

Comments
 (0)