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 129c337
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 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 @@ -12,33 +13,32 @@ pub struct Entry {

impl Entry {
/// Create a new `Entry`.
pub fn new(name: impl AsRef<str>, body: impl Into<Body>) -> Self {
pub fn new<S, B>(name: S, body: B) -> Self
where
S: AsRef<str>,
B: Into<Body>,
{
Self {
name: name.as_ref().to_owned(),
body: body.into(),
}
}

/// Create an empty `Entry`.
pub fn empty(name: impl AsRef<str>) -> Self {
Self {
name: name.as_ref().to_owned(),
body: Body::empty(),
}
pub fn empty<S>(name: S) -> Self
where
S: AsRef<str>,
{
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 129c337

Please sign in to comment.