From 939fc436d2e8ebb20c501ee600a7eb7ce6c4f25b Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Mon, 28 Sep 2020 12:38:48 +0200 Subject: [PATCH] Fix Entry::from_file --- src/multipart/entry.rs | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/multipart/entry.rs b/src/multipart/entry.rs index 73ddbec9..dcbd429e 100644 --- a/src/multipart/entry.rs +++ b/src/multipart/entry.rs @@ -1,6 +1,7 @@ -use crate::{bail, Body, Mime}; +use crate::{Body, Mime}; use std::fmt::{self, Debug}; +use std::path::Path; /// A single multipart entry. /// @@ -21,24 +22,16 @@ impl Entry { /// Create an empty `Entry`. pub fn empty(name: impl AsRef) -> Self { - Self { - name: name.as_ref().to_owned(), - body: Body::empty(), - } + Self::new(name, Body::empty()) } /// Create an `Entry` from a file. - /// #[cfg(all(feature = "async_std", not(target_os = "unknown")))] - pub async fn from_file

(path: P) -> crate::Result + pub async fn from_file(name: S, path: P) -> crate::Result where - P: AsRef, + S: AsRef, + P: AsRef, { - let path = path.as_ref(); - let name = match path.to_str() { - Some(p) => p.to_owned(), - None => bail!("Could not convert file name to unicode"), - }; let body = Body::from_file(path).await?; Ok(Self::new(name, body)) }