Remove generics for Link and Message
This commit is contained in:
parent
42afaf4e6a
commit
8b0af76b8f
2 changed files with 16 additions and 41 deletions
|
@ -5,13 +5,12 @@ use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
|
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
|
||||||
pub struct Link<T: Display + PartialEq> {
|
pub struct Link {
|
||||||
pub url: T,
|
pub url: String,
|
||||||
pub display: Option<T>,
|
pub display: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Display for Link<T>
|
impl Display for Link {
|
||||||
where T: Display + PartialEq {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match &self.display {
|
match &self.display {
|
||||||
Some(d) => write!(f, "=> {} {d}", self.url),
|
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;
|
type Err = super::Error;
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
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 })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::prelude::{Host, Mailbox};
|
use crate::prelude::{Host, Mailbox};
|
||||||
use std::{fmt, str::FromStr, io::BufRead};
|
use std::{fmt, str::FromStr};
|
||||||
|
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -22,21 +22,20 @@ impl fmt::Display for Recipients {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum Lines<T: fmt::Display + PartialEq> {
|
pub enum Lines {
|
||||||
Sender(Mailbox),
|
Sender(Mailbox),
|
||||||
Recipients(Recipients),
|
Recipients(Recipients),
|
||||||
Timestamp(T),
|
Timestamp(String),
|
||||||
Text(T),
|
Text(String),
|
||||||
Heading1(T),
|
Heading1(String),
|
||||||
Heading2(T),
|
Heading2(String),
|
||||||
Heading3(T),
|
Heading3(String),
|
||||||
Quote(T),
|
Quote(String),
|
||||||
Preformatted(T),
|
Preformatted(String),
|
||||||
Link(Link<T>),
|
Link(Link),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> fmt::Display for Lines<T>
|
impl fmt::Display for Lines {
|
||||||
where T: fmt::Display + PartialEq + BufRead {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Self::Sender(m) => writeln!(f, "< {m}"),
|
Self::Sender(m) => writeln!(f, "< {m}"),
|
||||||
|
|
Loading…
Add table
Reference in a new issue