1use errors::{Error, Result};
2use extern_mime;
3use serde;
4use std::fmt;
5use std::result;
6use std::str::FromStr;
7
8#[derive(Debug, Clone)]
9pub struct Mime(extern_mime::Mime);
10
11impl serde::Serialize for Mime {
12 fn serialize<S>(&self, serializer: S) -> result::Result<S::Ok, S::Error>
13 where
14 S: serde::Serializer,
15 {
16 serializer.serialize_str(&format!("{}", self.0))
17 }
18}
19
20impl FromStr for Mime {
21 type Err = Error;
22
23 fn from_str(s: &str) -> Result<Self> {
24 Ok(Mime(s.parse()?))
25 }
26}
27
28impl fmt::Display for Mime {
29 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
30 write!(f, "{}", self.0)
31 }
32}