Remove generics for Link and Message

This commit is contained in:
Nathan Fisher 2023-06-01 10:41:00 -04:00
parent 42afaf4e6a
commit 8b0af76b8f
2 changed files with 16 additions and 41 deletions

View file

@ -5,13 +5,12 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
pub struct Link<T: Display + PartialEq> {
pub url: T,
pub display: Option<T>,
pub struct Link {
pub url: String,
pub display: Option<String>,
}
impl<T> Display for Link<T>
where T: Display + PartialEq {
impl Display for Link {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match &self.display {
Some(d) => write!(f, "=> {} {d}", self.url),
@ -20,7 +19,7 @@ where T: Display + PartialEq {
}
}
impl FromStr for Link<String> {
impl FromStr for Link {
type Err = super::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
@ -34,26 +33,3 @@ impl FromStr for Link<String> {
}
}
}
impl TryFrom<&str> for Link<String> {
type Error = super::Error;
fn try_from(value: &str) -> Result<Self, Self::Error> {
value.parse()
}
}
impl<'a> TryFrom<&'a str> for Link<&'a str> {
type Error = super::Error;
fn try_from(value: &'a str) -> Result<Self, Self::Error> {
let Some(s) = value.strip_prefix("=> ") else {
return Err(super::Error::MalformedLink);
};
if let Some((url, display)) = s.split_once(char::is_whitespace) {
Ok(Self { url, display: Some(display) })
} else {
Ok(Self { url: s , display: None })
}
}
}

View file

@ -1,5 +1,5 @@
use crate::prelude::{Host, Mailbox};
use std::{fmt, str::FromStr, io::BufRead};
use std::{fmt, str::FromStr};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
@ -22,21 +22,20 @@ impl fmt::Display for Recipients {
}
#[derive(Clone, Debug, PartialEq)]
pub enum Lines<T: fmt::Display + PartialEq> {
pub enum Lines {
Sender(Mailbox),
Recipients(Recipients),
Timestamp(T),
Text(T),
Heading1(T),
Heading2(T),
Heading3(T),
Quote(T),
Preformatted(T),
Link(Link<T>),
Timestamp(String),
Text(String),
Heading1(String),
Heading2(String),
Heading3(String),
Quote(String),
Preformatted(String),
Link(Link),
}
impl<T> fmt::Display for Lines<T>
where T: fmt::Display + PartialEq + BufRead {
impl fmt::Display for Lines {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Sender(m) => writeln!(f, "< {m}"),