Body from tokio::fs::File (#1360)

This commit is contained in:
Fredrik Enestad
2021-10-22 00:23:17 +02:00
committed by GitHub
parent be8ab7b951
commit ab49de875e
2 changed files with 13 additions and 1 deletions

View File

@@ -58,7 +58,7 @@ multipart = ["mime_guess"]
trust-dns = ["trust-dns-resolver"]
stream = []
stream = ["tokio/fs", "tokio-util"]
socks = ["tokio-socks"]

View File

@@ -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()