Body from tokio::fs::File (#1360)
This commit is contained in:
@@ -58,7 +58,7 @@ multipart = ["mime_guess"]
|
||||
|
||||
trust-dns = ["trust-dns-resolver"]
|
||||
|
||||
stream = []
|
||||
stream = ["tokio/fs", "tokio-util"]
|
||||
|
||||
socks = ["tokio-socks"]
|
||||
|
||||
|
||||
@@ -7,7 +7,11 @@ use bytes::Bytes;
|
||||
use futures_core::Stream;
|
||||
use http_body::Body as HttpBody;
|
||||
use pin_project_lite::pin_project;
|
||||
#[cfg(feature = "stream")]
|
||||
use tokio::fs::File;
|
||||
use tokio::time::Sleep;
|
||||
#[cfg(feature = "stream")]
|
||||
use tokio_util::io::ReaderStream;
|
||||
|
||||
/// An asynchronous request body.
|
||||
pub struct Body {
|
||||
@@ -208,6 +212,14 @@ impl From<&'static str> for Body {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "stream")]
|
||||
impl From<File> for Body {
|
||||
#[inline]
|
||||
fn from(file: File) -> Body {
|
||||
Body::wrap_stream(ReaderStream::new(file))
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for Body {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.debug_struct("Body").finish()
|
||||
|
||||
Reference in New Issue
Block a user