Skip to main content

io_email/
address.rs

1//! Email address shared across all protocols.
2
3use alloc::string::String;
4
5/// A single email address with an optional display name.
6///
7/// Common shape used by every protocol-specific envelope and message
8/// representation in this crate.
9#[derive(Clone, Debug, PartialEq, Eq, Hash)]
10#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
11#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))]
12pub struct Address {
13    /// Display name (e.g. `Alice`), if any.
14    pub name: Option<String>,
15
16    /// Email address (e.g. `alice@example.org`).
17    pub email: String,
18}
19
20impl Address {
21    pub fn new(email: impl Into<String>) -> Self {
22        Self {
23            name: None,
24            email: email.into(),
25        }
26    }
27
28    pub fn with_name(mut self, name: impl Into<String>) -> Self {
29        self.name = Some(name.into());
30        self
31    }
32}