1- use async_std:: io:: prelude:: * ;
2- use async_std:: io:: { self , Cursor } ;
1+ use futures_lite:: * ;
32use serde:: { de:: DeserializeOwned , Serialize } ;
43
54use 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 ( ) ;
0 commit comments