Skip to content

Commit

Permalink
Update to tokio 1.0, bytes 1.0 (seanmonstar#1076)
Browse files Browse the repository at this point in the history
Co-authored-by: Wim Looman <git@nemo157.com>
Co-authored-by: Paolo Barbolini <paolo@paolo565.org>
  • Loading branch information
3 people authored and pfernie committed Jan 5, 2021
1 parent 9cfa755 commit f93ddb2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
2 changes: 0 additions & 2 deletions src/async_impl/client.rs
Expand Up @@ -17,13 +17,11 @@ use hyper::client::ResponseFuture;
#[cfg(feature = "native-tls-crate")]
use native_tls_crate::TlsConnector;
use pin_project_lite::pin_project;
use pin_project_lite::pin_project;
#[cfg(feature = "rustls-tls-native-roots")]
use rustls::RootCertStore;
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};
use tokio::time::Delay;
use tokio::time::Sleep;

use log::debug;
Expand Down
15 changes: 6 additions & 9 deletions src/blocking/body.rs
@@ -1,14 +1,14 @@
use std::fmt;
use std::fs::File;
use std::future::Future;
use std::io::{self, Read};
#[cfg(feature = "multipart")]
use std::io::Cursor;
use std::io::{self, Read};
use std::mem;
use std::ptr;

use bytes::Bytes;
use bytes::buf::UninitSlice;
use bytes::Bytes;

use crate::async_impl;

Expand Down Expand Up @@ -95,7 +95,7 @@ impl Body {
/// Converts streamed requests to their buffered equivalent and
/// returns a reference to the buffer. If the request is already
/// buffered, this has no effect.
///
///
/// Be aware that for large requests this method is expensive
/// and may cause your program to run out of memory.
pub fn buffer(&mut self) -> Result<&[u8], crate::Error> {
Expand All @@ -106,11 +106,10 @@ impl Body {
} else {
Vec::new()
};
io::copy(reader, &mut bytes)
.map_err(crate::error::builder)?;
io::copy(reader, &mut bytes).map_err(crate::error::builder)?;
self.kind = Kind::Bytes(bytes.into());
self.buffer()
},
}
Kind::Bytes(ref bytes) => Ok(bytes.as_ref()),
}
}
Expand Down Expand Up @@ -302,9 +301,7 @@ async fn send_future(sender: Sender) -> Result<(), crate::Error> {
}
}

let bytes = unsafe {
mem::transmute::<&mut UninitSlice, &mut [u8]>(buf.chunk_mut())
};
let bytes = unsafe { mem::transmute::<&mut UninitSlice, &mut [u8]>(buf.chunk_mut()) };
match body.read(bytes) {
Ok(0) => {
// The buffer was empty and nothing's left to
Expand Down

0 comments on commit f93ddb2

Please sign in to comment.