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 {
pub fn as_str(&self) -> &'static str {
use EmailCharset::*;

View file

@ -101,6 +101,11 @@ pub struct Multipart {
pub subtype: MultipartSubtype,
pub boundary: String,
}
impl Multipart {
pub fn main_type(&self) -> String {
"multipart".into()
}
}
impl<'a> TryFrom<&'a NaiveType<'a>> for Multipart {
type Error = ();
@ -125,6 +130,18 @@ pub enum MultipartSubtype {
Report,
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 {
fn from(nt: &NaiveType<'a>) -> Self {
match nt.sub.to_ascii_lowercase().as_slice() {
@ -148,6 +165,16 @@ pub enum MessageSubtype {
External,
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>;
#[derive(Debug, PartialEq, Default, Clone)]
@ -206,6 +233,14 @@ pub enum TextSubtype {
Html,
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 {
fn from(nt: &NaiveType<'a>) -> Self {
match nt.sub.to_ascii_lowercase().as_slice() {