1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#[doc(hidden)]
pub mod polyfill;
pub use error::{FromContentError, ToContentError};
pub use mime_ext::MimeExt;
#[cfg(feature = "encoding")]
mod encoding;
mod error;
mod mime_ext;
#[cfg(any(feature = "serde-base", feature = "serde-full"))]
mod serde_support;
#[cfg(feature = "unhtml-html")]
mod unhtml_support;
use crate::mime::Mime;
pub trait FromContent: Sized {
fn from_content(data: Vec<u8>, content_type: &Mime) -> Result<Self, FromContentError>;
}
pub trait ToContent {
fn to_content(&self, content_type: &Mime) -> Result<Vec<u8>, ToContentError>;
}
pub trait ContentInto<T: Sized> {
fn content_into(self, content_type: &Mime) -> Result<T, FromContentError>;
}
impl<T: FromContent> ContentInto<T> for Vec<u8> {
fn content_into(self, content_type: &Mime) -> Result<T, FromContentError> {
<T as FromContent>::from_content(self, content_type)
}
}
mod impls {
use crate::mime::Mime;
use crate::{FromContent, FromContentError, ToContent, ToContentError};
impl FromContent for () {
fn from_content(_data: Vec<u8>, _content_type: &Mime) -> Result<Self, FromContentError> {
Ok(())
}
}
impl ToContent for () {
fn to_content(&self, _content_type: &Mime) -> Result<Vec<u8>, ToContentError> {
Ok(Vec::new())
}
}
}