From 5abf064770e98e26cc55a7f2ea42e8f03283f0e0 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Tue, 11 Sep 2018 13:38:02 -0700 Subject: [PATCH] change multipart::Part::mime() to mime_str() The mime crate is expecting a breaking change to 0.4, so to remove the public dependency, this method is changed to `mime_str`, which will parse a MIME string instead. --- src/error.rs | 16 +++++++++++++--- src/multipart.rs | 8 ++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/error.rs b/src/error.rs index 1ac9dd8..3c817fd 100644 --- a/src/error.rs +++ b/src/error.rs @@ -113,6 +113,7 @@ impl Error { match self.kind { Kind::Http(ref e) => Some(e), Kind::Hyper(ref e) => Some(e), + Kind::Mime(ref e) => Some(e), Kind::Url(ref e) => Some(e), Kind::Tls(ref e) => Some(e), Kind::Io(ref e) => Some(e), @@ -193,6 +194,7 @@ impl fmt::Display for Error { match self.kind { Kind::Http(ref e) => fmt::Display::fmt(e, f), Kind::Hyper(ref e) => fmt::Display::fmt(e, f), + Kind::Mime(ref e) => fmt::Display::fmt(e, f), Kind::Url(ref e) => fmt::Display::fmt(e, f), Kind::Tls(ref e) => fmt::Display::fmt(e, f), Kind::Io(ref e) => fmt::Display::fmt(e, f), @@ -217,6 +219,7 @@ impl StdError for Error { match self.kind { Kind::Http(ref e) => e.description(), Kind::Hyper(ref e) => e.description(), + Kind::Mime(ref e) => e.description(), Kind::Url(ref e) => e.description(), Kind::Tls(ref e) => e.description(), Kind::Io(ref e) => e.description(), @@ -233,6 +236,7 @@ impl StdError for Error { match self.kind { Kind::Http(ref e) => e.cause(), Kind::Hyper(ref e) => e.cause(), + Kind::Mime(ref e) => e.cause(), Kind::Url(ref e) => e.cause(), Kind::Tls(ref e) => e.cause(), Kind::Io(ref e) => e.cause(), @@ -252,6 +256,7 @@ impl StdError for Error { pub enum Kind { Http(::http::Error), Hyper(::hyper::Error), + Mime(::mime::FromStrError), Url(::url::ParseError), Tls(::native_tls::Error), Io(io::Error), @@ -274,9 +279,14 @@ impl From<::http::Error> for Kind { impl From<::hyper::Error> for Kind { #[inline] fn from(err: ::hyper::Error) -> Kind { - match err { - other => Kind::Hyper(other), - } + Kind::Hyper(err) + } +} + +impl From<::mime::FromStrError> for Kind { + #[inline] + fn from(err: ::mime::FromStrError) -> Kind { + Kind::Mime(err) } } diff --git a/src/multipart.rs b/src/multipart.rs index 4199f2d..20375f9 100644 --- a/src/multipart.rs +++ b/src/multipart.rs @@ -191,11 +191,19 @@ impl Part { } } + /// Tries to set the mime of this part. + pub fn mime_str(mut self, mime: &str) -> ::Result { + self.mime = Some(try_!(mime.parse())); + Ok(self) + } + + /* Re-enable when mime 0.4 is available, with split MediaType/MediaRange. /// Sets the mime, builder style. pub fn mime(mut self, mime: Mime) -> Part { self.mime = Some(mime); self } + */ /// Sets the filename, builder style. pub fn file_name>>(mut self, filename: T) -> Part {