pub struct Email(/* private fields */);Available on crate feature
net only.Expand description
An email address.
This type provides type-safe email addresses with RFC 5322 validation.
It uses the newtype pattern with #[repr(transparent)] for zero-cost abstraction.
§Invariants
- Total length is 1-254 characters
- Local part is 1-64 characters
- Domain part follows RFC 1035 domain name rules
- Contains exactly one @ symbol
- Domain part is stored in lowercase for case-insensitive comparison
- Local part is case-sensitive (preserved as-is)
§Examples
use bare_types::net::Email;
// Create an email
let email = Email::new("user@example.com")?;
// Access the string representation
assert_eq!(email.as_str(), "user@example.com");
// Get the local part
assert_eq!(email.local_part(), "user");
// Get the domain part
assert_eq!(email.domain_part(), "example.com");
// Parse from string
let email: Email = "user@example.com".parse()?;Implementations§
Source§impl Email
impl Email
Sourcepub fn new(s: &str) -> Result<Self, EmailError>
pub fn new(s: &str) -> Result<Self, EmailError>
Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Returns the email address as a string slice.
§Examples
use bare_types::net::Email;
let email = Email::new("user@example.com").unwrap();
assert_eq!(email.as_str(), "user@example.com");Sourcepub const fn as_inner(&self) -> &String<254>
pub const fn as_inner(&self) -> &String<254>
Returns a reference to the underlying heapless::String.
§Examples
use bare_types::net::Email;
let email = Email::new("user@example.com").unwrap();
let inner: &heapless::String<254> = email.as_inner();
assert_eq!(inner.as_str(), "user@example.com");Sourcepub fn into_inner(self) -> String<254>
pub fn into_inner(self) -> String<254>
Consumes this email and returns the underlying string.
§Examples
use bare_types::net::Email;
let email = Email::new("user@example.com").unwrap();
let inner = email.into_inner();
assert_eq!(inner.as_str(), "user@example.com");Sourcepub fn local_part(&self) -> &str
pub fn local_part(&self) -> &str
Returns the local part of the email address (before @).
§Examples
use bare_types::net::Email;
let email = Email::new("user@example.com").unwrap();
assert_eq!(email.local_part(), "user");Sourcepub fn domain_part(&self) -> &str
pub fn domain_part(&self) -> &str
Returns the domain part of the email address (after @).
§Examples
use bare_types::net::Email;
let email = Email::new("user@example.com").unwrap();
assert_eq!(email.domain_part(), "example.com");Trait Implementations§
Source§impl<'a> Arbitrary<'a> for Email
Available on crate feature arbitrary only.
impl<'a> Arbitrary<'a> for Email
Available on crate feature
arbitrary only.Source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
Generate an arbitrary value of
Self from the given unstructured data. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Generate an arbitrary value of
Self from the entirety of the given
unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Get a size hint for how many bytes out of an
Unstructured this type
needs to construct itself. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Get a size hint for how many bytes out of an
Unstructured this type
needs to construct itself. Read moreSource§impl<'de> Deserialize<'de> for Email
impl<'de> Deserialize<'de> for Email
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Ord for Email
impl Ord for Email
Source§impl PartialOrd for Email
impl PartialOrd for Email
impl Eq for Email
impl StructuralPartialEq for Email
Auto Trait Implementations§
impl Freeze for Email
impl RefUnwindSafe for Email
impl Send for Email
impl Sync for Email
impl Unpin for Email
impl UnwindSafe for Email
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more