Add FromStr
for Recipients
This commit is contained in:
parent
4b43b283dd
commit
98c8d2ac6e
2 changed files with 25 additions and 2 deletions
|
@ -1,4 +1,4 @@
|
|||
use {crate::prelude::ParseHostError, std::fmt};
|
||||
use {crate::prelude::{ParseHostError, ParseMailboxError}, std::fmt};
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
/// Errors which can occur when parsing a request
|
||||
|
@ -8,6 +8,7 @@ pub enum Error {
|
|||
EmptyHost,
|
||||
EmptyMessage,
|
||||
ParseHostError(ParseHostError),
|
||||
ParseMailboxError(ParseMailboxError),
|
||||
MalformedLink,
|
||||
}
|
||||
|
||||
|
@ -34,3 +35,9 @@ impl From<ParseHostError> for Error {
|
|||
Self::ParseHostError(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ParseMailboxError> for Error {
|
||||
fn from(value: ParseMailboxError) -> Self {
|
||||
Self::ParseMailboxError(value)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::prelude::{Host, Mailbox};
|
||||
use crate::prelude::Mailbox;
|
||||
use std::{fmt, str::FromStr};
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
|
@ -25,6 +25,22 @@ impl fmt::Display for Recipients {
|
|||
}
|
||||
}
|
||||
|
||||
impl FromStr for Recipients {
|
||||
type Err = Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
let mut rec = Recipients { boxes: vec![] };
|
||||
if let Some(s) = s.strip_prefix(':') {
|
||||
s.split_whitespace().try_for_each(|r| {
|
||||
let r = r.parse()?;
|
||||
rec.boxes.push(r);
|
||||
Ok::<(), Error>(())
|
||||
})?;
|
||||
}
|
||||
Ok(rec)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
|
||||
pub struct Message {
|
||||
|
|
Loading…
Add table
Reference in a new issue