Skip to content

Commit c124be5

Browse files
akhillesjbr
authored andcommitted
async_std::io -> futures_lite
1 parent 82e3d5e commit c124be5

File tree

8 files changed

+46
-56
lines changed

8 files changed

+46
-56
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ cookie-secure = ["cookie/secure"]
2727
# Note(yoshuawuyts): used for async_std's `channel` only; use "core" once possible.
2828
# features: async_std
2929
async-std = { version = "1.6.0", features = ["unstable"] }
30+
futures-lite = "1.7.0"
3031

3132
# features: hyperium/http
3233
http = { version = "0.2.0", optional = true }

src/body.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use async_std::io::prelude::*;
2-
use async_std::io::{self, Cursor};
1+
use futures_lite::*;
32
use serde::{de::DeserializeOwned, Serialize};
43

54
use std::fmt::{self, Debug};
@@ -54,7 +53,7 @@ pin_project_lite::pin_project! {
5453
/// and not rely on the fallback mechanisms. However, they're still there if you need them.
5554
pub struct Body {
5655
#[pin]
57-
reader: Box<dyn BufRead + Unpin + Send + Sync + 'static>,
56+
reader: Box<dyn AsyncBufRead + Unpin + Send + Sync + 'static>,
5857
mime: Mime,
5958
length: Option<usize>,
6059
}
@@ -76,7 +75,7 @@ impl Body {
7675
/// ```
7776
pub fn empty() -> Self {
7877
Self {
79-
reader: Box::new(io::empty()),
78+
reader: Box::new(io::Cursor::new(Vec::new())),
8079
mime: mime::BYTE_STREAM,
8180
length: Some(0),
8281
}
@@ -102,7 +101,7 @@ impl Body {
102101
/// req.set_body(Body::from_reader(cursor, Some(len)));
103102
/// ```
104103
pub fn from_reader(
105-
reader: impl BufRead + Unpin + Send + Sync + 'static,
104+
reader: impl AsyncBufRead + Unpin + Send + Sync + 'static,
106105
len: Option<usize>,
107106
) -> Self {
108107
Self {
@@ -125,7 +124,7 @@ impl Body {
125124
/// let body = Body::from_reader(cursor, None);
126125
/// let _ = body.into_reader();
127126
/// ```
128-
pub fn into_reader(self) -> Box<dyn BufRead + Unpin + Send + Sync + 'static> {
127+
pub fn into_reader(self) -> Box<dyn AsyncBufRead + Unpin + Send + Sync + 'static> {
129128
self.reader
130129
}
131130

@@ -160,7 +159,7 @@ impl Body {
160159
/// # Examples
161160
///
162161
/// ```
163-
/// # fn main() -> Result<(), http_types::Error> { async_std::task::block_on(async {
162+
/// # fn main() -> http_types::Result<()> { async_std::task::block_on(async {
164163
/// use http_types::Body;
165164
///
166165
/// let bytes = vec![1, 2, 3];
@@ -209,9 +208,7 @@ impl Body {
209208
/// # Examples
210209
///
211210
/// ```
212-
/// # use std::io::prelude::*;
213-
/// # fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
214-
/// # async_std::task::block_on(async {
211+
/// # fn main() -> http_types::Result<()> { async_std::task::block_on(async {
215212
/// use http_types::Body;
216213
/// use async_std::io::Cursor;
217214
///
@@ -246,7 +243,7 @@ impl Body {
246243
let bytes = serde_json::to_vec(&json)?;
247244
let body = Self {
248245
length: Some(bytes.len()),
249-
reader: Box::new(Cursor::new(bytes)),
246+
reader: Box::new(io::Cursor::new(bytes)),
250247
mime: mime::JSON,
251248
};
252249
Ok(body)
@@ -257,7 +254,7 @@ impl Body {
257254
/// # Examples
258255
///
259256
/// ```
260-
/// # fn main() -> Result<(), http_types::Error> { async_std::task::block_on(async {
257+
/// # fn main() -> http_types::Result<()> { async_std::task::block_on(async {
261258
/// use http_types::Body;
262259
/// use http_types::convert::{Serialize, Deserialize};
263260
///
@@ -290,7 +287,7 @@ impl Body {
290287
/// # Examples
291288
///
292289
/// ```
293-
/// # fn main() -> Result<(), http_types::Error> { async_std::task::block_on(async {
290+
/// # fn main() -> http_types::Result<()> { async_std::task::block_on(async {
294291
/// use http_types::Body;
295292
/// use http_types::convert::{Serialize, Deserialize};
296293
///
@@ -310,7 +307,7 @@ impl Body {
310307

311308
let body = Self {
312309
length: Some(bytes.len()),
313-
reader: Box::new(Cursor::new(bytes)),
310+
reader: Box::new(io::Cursor::new(bytes)),
314311
mime: mime::FORM,
315312
};
316313
Ok(body)
@@ -326,7 +323,7 @@ impl Body {
326323
/// # Examples
327324
///
328325
/// ```
329-
/// # fn main() -> Result<(), http_types::Error> { async_std::task::block_on(async {
326+
/// # fn main() -> http_types::Result<()> { async_std::task::block_on(async {
330327
/// use http_types::Body;
331328
/// use http_types::convert::{Serialize, Deserialize};
332329
///
@@ -353,7 +350,7 @@ impl Body {
353350
/// # Examples
354351
///
355352
/// ```no_run
356-
/// # fn main() -> Result<(), http_types::Error> { async_std::task::block_on(async {
353+
/// # fn main() -> http_types::Result<()> { async_std::task::block_on(async {
357354
/// use http_types::{Body, Response, StatusCode};
358355
///
359356
/// let mut res = Response::new(StatusCode::Ok);
@@ -455,7 +452,7 @@ impl<'a> From<&'a [u8]> for Body {
455452
}
456453
}
457454

458-
impl Read for Body {
455+
impl AsyncRead for Body {
459456
#[allow(missing_doc_code_examples)]
460457
fn poll_read(
461458
mut self: Pin<&mut Self>,
@@ -466,7 +463,7 @@ impl Read for Body {
466463
}
467464
}
468465

469-
impl BufRead for Body {
466+
impl AsyncBufRead for Body {
470467
#[allow(missing_doc_code_examples)]
471468
fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<&'_ [u8]>> {
472469
let this = self.project();

src/request.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use async_std::io::{self, BufRead, Read};
21
use async_std::sync;
2+
use futures_lite::*;
33

44
use std::convert::{Into, TryInto};
55
use std::mem;
@@ -207,8 +207,7 @@ impl Request {
207207
///
208208
/// ```
209209
/// # use async_std::io::prelude::*;
210-
/// # fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
211-
/// # async_std::task::block_on(async {
210+
/// # fn main() -> http_types::Result<()> { async_std::task::block_on(async {
212211
/// #
213212
/// use http_types::{Body, Method, Request, Url};
214213
///
@@ -234,8 +233,7 @@ impl Request {
234233
///
235234
/// ```
236235
/// # use async_std::io::prelude::*;
237-
/// # fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
238-
/// # async_std::task::block_on(async {
236+
/// # fn main() -> http_types::Result<()> { async_std::task::block_on(async {
239237
/// #
240238
/// use http_types::{Body, Method, Request, Url};
241239
///
@@ -261,8 +259,7 @@ impl Request {
261259
///
262260
/// ```
263261
/// # use async_std::io::prelude::*;
264-
/// # fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
265-
/// # async_std::task::block_on(async {
262+
/// # fn main() -> http_types::Result<()> { async_std::task::block_on(async {
266263
/// #
267264
/// use http_types::{Body, Method, Request, Url};
268265
///
@@ -295,8 +292,7 @@ impl Request {
295292
///
296293
/// ```
297294
/// # use std::io::prelude::*;
298-
/// # fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
299-
/// # async_std::task::block_on(async {
295+
/// # fn main() -> http_types::Result<()> { async_std::task::block_on(async {
300296
/// use async_std::io::Cursor;
301297
/// use http_types::{Body, Method, Request, Url};
302298
///
@@ -323,7 +319,7 @@ impl Request {
323319
/// # Examples
324320
///
325321
/// ```
326-
/// # fn main() -> Result<(), http_types::Error> { async_std::task::block_on(async {
322+
/// # fn main() -> http_types::Result<()> { async_std::task::block_on(async {
327323
/// use http_types::{Body, Method, Request, Url};
328324
///
329325
/// let bytes = vec![1, 2, 3];
@@ -349,7 +345,7 @@ impl Request {
349345
/// # Examples
350346
///
351347
/// ```
352-
/// # fn main() -> Result<(), http_types::Error> { async_std::task::block_on(async {
348+
/// # fn main() -> http_types::Result<()> { async_std::task::block_on(async {
353349
/// use http_types::convert::{Deserialize, Serialize};
354350
/// use http_types::{Body, Method, Request, Url};
355351
///
@@ -383,7 +379,7 @@ impl Request {
383379
/// # Examples
384380
///
385381
/// ```
386-
/// # fn main() -> Result<(), http_types::Error> { async_std::task::block_on(async {
382+
/// # fn main() -> http_types::Result<()> { async_std::task::block_on(async {
387383
/// use http_types::convert::{Deserialize, Serialize};
388384
/// use http_types::{Body, Method, Request, Url};
389385
///
@@ -886,7 +882,7 @@ impl Clone for Request {
886882
}
887883
}
888884

889-
impl Read for Request {
885+
impl AsyncRead for Request {
890886
#[allow(missing_doc_code_examples)]
891887
fn poll_read(
892888
mut self: Pin<&mut Self>,
@@ -897,7 +893,7 @@ impl Read for Request {
897893
}
898894
}
899895

900-
impl BufRead for Request {
896+
impl AsyncBufRead for Request {
901897
#[allow(missing_doc_code_examples)]
902898
fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<&'_ [u8]>> {
903899
let this = self.project();

src/response.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use async_std::io::{self, BufRead, Read};
21
use async_std::sync;
2+
use futures_lite::*;
33

44
use std::convert::{Into, TryInto};
55
use std::fmt::Debug;
@@ -231,8 +231,7 @@ impl Response {
231231
///
232232
/// ```
233233
/// # use async_std::io::prelude::*;
234-
/// # fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
235-
/// # async_std::task::block_on(async {
234+
/// # fn main() -> http_types::Result<()> { async_std::task::block_on(async {
236235
/// #
237236
/// use http_types::{Body, Method, Response, StatusCode, Url};
238237
///
@@ -260,8 +259,7 @@ impl Response {
260259
///
261260
/// ```
262261
/// # use async_std::io::prelude::*;
263-
/// # fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
264-
/// # async_std::task::block_on(async {
262+
/// # fn main() -> http_types::Result<()> { async_std::task::block_on(async {
265263
/// #
266264
/// use http_types::{Body, Method, Response, StatusCode, Url};
267265
///
@@ -288,8 +286,7 @@ impl Response {
288286
///
289287
/// ```
290288
/// # use async_std::io::prelude::*;
291-
/// # fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
292-
/// # async_std::task::block_on(async {
289+
/// # fn main() -> http_types::Result<()> { async_std::task::block_on(async {
293290
/// #
294291
/// use http_types::{Body, Method, Response, StatusCode, Url};
295292
///
@@ -322,8 +319,7 @@ impl Response {
322319
///
323320
/// ```
324321
/// # use std::io::prelude::*;
325-
/// # fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
326-
/// # async_std::task::block_on(async {
322+
/// # fn main() -> http_types::Result<()> { async_std::task::block_on(async {
327323
/// use async_std::io::Cursor;
328324
/// use http_types::{Body, Method, Response, StatusCode, Url};
329325
///
@@ -349,7 +345,7 @@ impl Response {
349345
/// # Examples
350346
///
351347
/// ```
352-
/// # fn main() -> Result<(), http_types::Error> { async_std::task::block_on(async {
348+
/// # fn main() -> http_types::Result<()> { async_std::task::block_on(async {
353349
/// use http_types::{Body, Method, Response, StatusCode, Url};
354350
///
355351
/// let bytes = vec![1, 2, 3];
@@ -375,7 +371,7 @@ impl Response {
375371
/// # Examples
376372
///
377373
/// ```
378-
/// # fn main() -> Result<(), http_types::Error> { async_std::task::block_on(async {
374+
/// # fn main() -> http_types::Result<()> { async_std::task::block_on(async {
379375
/// use http_types::convert::{Deserialize, Serialize};
380376
/// use http_types::{Body, Method, Response, StatusCode, Url};
381377
///
@@ -409,7 +405,7 @@ impl Response {
409405
/// # Examples
410406
///
411407
/// ```
412-
/// # fn main() -> Result<(), http_types::Error> { async_std::task::block_on(async {
408+
/// # fn main() -> http_types::Result<()> { async_std::task::block_on(async {
413409
/// use http_types::convert::{Deserialize, Serialize};
414410
/// use http_types::{Body, Method, Response, StatusCode, Url};
415411
///
@@ -665,7 +661,7 @@ impl Clone for Response {
665661
}
666662
}
667663

668-
impl Read for Response {
664+
impl AsyncRead for Response {
669665
#[allow(missing_doc_code_examples)]
670666
fn poll_read(
671667
mut self: Pin<&mut Self>,
@@ -676,7 +672,7 @@ impl Read for Response {
676672
}
677673
}
678674

679-
impl BufRead for Response {
675+
impl AsyncBufRead for Response {
680676
#[allow(missing_doc_code_examples)]
681677
fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<&'_ [u8]>> {
682678
let this = self.project();

src/trailers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050
use crate::headers::{
5151
HeaderName, HeaderValues, Headers, Iter, IterMut, Names, ToHeaderValues, Values,
5252
};
53-
use async_std::prelude::*;
5453
use async_std::sync;
54+
use futures_lite::*;
5555

5656
use std::convert::Into;
5757
use std::future::Future;

src/upgrade/connection.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use async_std::io::{self, prelude::*};
1+
use futures_lite::*;
22

33
use std::pin::Pin;
44
use std::task::{Context, Poll};
@@ -13,10 +13,10 @@ pub struct RawConnection<Inner> {
1313
pub type Connection = RawConnection<Box<dyn InnerConnection + 'static>>;
1414

1515
/// Trait to signal the requirements for an underlying connection type.
16-
pub trait InnerConnection: Read + Write + Send + Sync + Unpin {}
17-
impl<T: Read + Write + Send + Sync + Unpin> InnerConnection for T {}
16+
pub trait InnerConnection: AsyncRead + AsyncWrite + Send + Sync + Unpin {}
17+
impl<T: AsyncRead + AsyncWrite + Send + Sync + Unpin> InnerConnection for T {}
1818

19-
impl<Inner: Read + Unpin> Read for RawConnection<Inner> {
19+
impl<Inner: AsyncRead + Unpin> AsyncRead for RawConnection<Inner> {
2020
fn poll_read(
2121
mut self: Pin<&mut Self>,
2222
cx: &mut Context<'_>,
@@ -26,7 +26,7 @@ impl<Inner: Read + Unpin> Read for RawConnection<Inner> {
2626
}
2727
}
2828

29-
impl<Inner: Write + Unpin> Write for RawConnection<Inner> {
29+
impl<Inner: AsyncWrite + Unpin> AsyncWrite for RawConnection<Inner> {
3030
fn poll_write(
3131
mut self: Pin<&mut Self>,
3232
cx: &mut Context<'_>,

src/upgrade/receiver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use async_std::prelude::*;
21
use async_std::sync;
2+
use futures_lite::*;
33

44
use std::future::Future;
55
use std::pin::Pin;

tests/req_res_body.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use async_std::io::prelude::*;
1+
use futures_lite::*;
22
use http_types::{Body, Method, Request, Response, StatusCode, Url};
33

44
#[test]
@@ -7,7 +7,7 @@ fn test_req_res_set_body() {
77
req.set_body(Body::empty());
88
let mut res = Response::new(StatusCode::Ok);
99
res.set_body(req);
10-
let body = async_std::task::block_on(async move {
10+
let body = future::block_on(async move {
1111
let mut body = Vec::new();
1212
res.read_to_end(&mut body).await.unwrap();
1313
body
@@ -21,7 +21,7 @@ fn test_req_res_take_replace_body() {
2121
req.take_body();
2222
let mut res = Response::new(StatusCode::Ok);
2323
res.replace_body(req);
24-
let body = async_std::task::block_on(async move {
24+
let body = future::block_on(async move {
2525
let mut body = Vec::new();
2626
res.read_to_end(&mut body).await.unwrap();
2727
body

0 commit comments

Comments
 (0)