Skip to content

Commit

Permalink
Fix Entry::from_file
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshuawuyts committed Sep 28, 2020
1 parent a03ac12 commit 939fc43
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/multipart/entry.rs
Original file line number Diff line number Diff line change
@@ -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.
///
Expand All @@ -21,24 +22,16 @@ impl Entry {

/// Create an empty `Entry`.
pub fn empty(name: impl AsRef<str>) -> 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<P>(path: P) -> crate::Result<Self>
pub async fn from_file<S, P>(name: S, path: P) -> crate::Result<Self>
where
P: AsRef<std::path::Path>,
S: AsRef<str>,
P: AsRef<Path>,
{
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))
}
Expand Down

0 comments on commit 939fc43

Please sign in to comment.