Skip to content

Commit

Permalink
Body from tokio::fs::File (#1360)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredr committed Oct 21, 2021
1 parent be8ab7b commit ab49de8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ multipart = ["mime_guess"]

trust-dns = ["trust-dns-resolver"]

stream = []
stream = ["tokio/fs", "tokio-util"]

socks = ["tokio-socks"]

Expand Down
12 changes: 12 additions & 0 deletions src/async_impl/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit ab49de8

Please sign in to comment.