From 8b0af76b8f6920ae43f6a9ba96b445864f42332a Mon Sep 17 00:00:00 2001 From: Nathan Fisher Date: Thu, 1 Jun 2023 10:41:00 -0400 Subject: [PATCH] Remove generics for Link and Message --- src/message/link.rs | 34 +++++----------------------------- src/message/mod.rs | 23 +++++++++++------------ 2 files changed, 16 insertions(+), 41 deletions(-) diff --git a/src/message/link.rs b/src/message/link.rs index 1bbbf05..2ee0e92 100644 --- a/src/message/link.rs +++ b/src/message/link.rs @@ -5,13 +5,12 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, PartialEq)] #[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] -pub struct Link { - pub url: T, - pub display: Option, +pub struct Link { + pub url: String, + pub display: Option, } -impl Display for Link -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 { +impl FromStr for Link { type Err = super::Error; fn from_str(s: &str) -> Result { @@ -34,26 +33,3 @@ impl FromStr for Link { } } } - -impl TryFrom<&str> for Link { - type Error = super::Error; - - fn try_from(value: &str) -> Result { - value.parse() - } -} - -impl<'a> TryFrom<&'a str> for Link<&'a str> { - type Error = super::Error; - - fn try_from(value: &'a str) -> Result { - 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 }) - } - } -} diff --git a/src/message/mod.rs b/src/message/mod.rs index b8e39a3..35554ec 100644 --- a/src/message/mod.rs +++ b/src/message/mod.rs @@ -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 { +pub enum Lines { Sender(Mailbox), Recipients(Recipients), - Timestamp(T), - Text(T), - Heading1(T), - Heading2(T), - Heading3(T), - Quote(T), - Preformatted(T), - Link(Link), + Timestamp(String), + Text(String), + Heading1(String), + Heading2(String), + Heading3(String), + Quote(String), + Preformatted(String), + Link(Link), } -impl fmt::Display for Lines -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}"),