implement to_string for some types

This commit is contained in:
Quentin 2023-07-25 14:39:30 +02:00
parent 64407b6bee
commit 91fa0d38c3
Signed by: quentin
GPG key ID: E9602264D639FF68
2 changed files with 41 additions and 0 deletions

View file

@ -77,6 +77,12 @@ impl<'a> From<&'a [u8]> for EmailCharset {
} }
} }
impl ToString for EmailCharset {
fn to_string(&self) -> String {
self.as_str().into()
}
}
impl EmailCharset { impl EmailCharset {
pub fn as_str(&self) -> &'static str { pub fn as_str(&self) -> &'static str {
use EmailCharset::*; use EmailCharset::*;

View file

@ -101,6 +101,11 @@ pub struct Multipart {
pub subtype: MultipartSubtype, pub subtype: MultipartSubtype,
pub boundary: String, pub boundary: String,
} }
impl Multipart {
pub fn main_type(&self) -> String {
"multipart".into()
}
}
impl<'a> TryFrom<&'a NaiveType<'a>> for Multipart { impl<'a> TryFrom<&'a NaiveType<'a>> for Multipart {
type Error = (); type Error = ();
@ -125,6 +130,18 @@ pub enum MultipartSubtype {
Report, Report,
Unknown, Unknown,
} }
impl ToString for MultipartSubtype {
fn to_string(&self) -> String {
match self {
Self::Alternative => "alternative",
Self::Mixed => "mixed",
Self::Digest => "digest",
Self::Parallel => "parallel",
Self::Report => "report",
Self::Unknown => "mixed",
}.into()
}
}
impl<'a> From<&NaiveType<'a>> for MultipartSubtype { impl<'a> From<&NaiveType<'a>> for MultipartSubtype {
fn from(nt: &NaiveType<'a>) -> Self { fn from(nt: &NaiveType<'a>) -> Self {
match nt.sub.to_ascii_lowercase().as_slice() { match nt.sub.to_ascii_lowercase().as_slice() {
@ -148,6 +165,16 @@ pub enum MessageSubtype {
External, External,
Unknown, Unknown,
} }
impl ToString for MessageSubtype {
fn to_string(&self) -> String {
match self {
Self::RFC822 => "rfc822",
Self::Partial => "partial",
Self::External => "external",
Self::Unknown => "rfc822",
}.into()
}
}
pub type DeductibleMessage = Deductible<Message>; pub type DeductibleMessage = Deductible<Message>;
#[derive(Debug, PartialEq, Default, Clone)] #[derive(Debug, PartialEq, Default, Clone)]
@ -206,6 +233,14 @@ pub enum TextSubtype {
Html, Html,
Unknown, Unknown,
} }
impl ToString for TextSubtype {
fn to_string(&self) -> String {
match self {
Self::Plain | Self::Unknown => "plain",
Self::Html => "html",
}.into()
}
}
impl<'a> From<&NaiveType<'a>> for TextSubtype { impl<'a> From<&NaiveType<'a>> for TextSubtype {
fn from(nt: &NaiveType<'a>) -> Self { fn from(nt: &NaiveType<'a>) -> Self {
match nt.sub.to_ascii_lowercase().as_slice() { match nt.sub.to_ascii_lowercase().as_slice() {