Skip to main content

Module email

Module email 

Source
Available on crate feature net only.
Expand description

Email address type for network programming.

This module provides a type-safe abstraction for email addresses, ensuring compliance with RFC 5322 email address specifications.

§RFC 5322 Email Address Rules

According to RFC 5322 §3.4.1:

  • Total length: up to 254 characters (RFC 5321 §4.5.3.1.1)
  • Local part: up to 64 characters (RFC 5321 §4.5.3.1.1)
  • Domain part: up to 255 characters (RFC 5321 §4.5.3.1.1)
  • Must contain exactly one @ symbol
  • Local part can contain: letters, digits, and special characters (! # $ % & ’ * + - / = ? ^ _ { | } ~) and backtick (`)
  • Local part can contain dots (.), but not at the start or end, and not consecutively
  • Local part can be quoted with double quotes for special characters
  • Domain part follows RFC 1035 domain name rules
  • Domain part is case-insensitive (stored in lowercase)
  • Local part is case-sensitive (preserved as-is)

§Examples

use bare_types::net::Email;

// Create an email
let email = Email::new("user@example.com")?;

// Get the local part
assert_eq!(email.local_part(), "user");

// Get the domain part
assert_eq!(email.domain_part(), "example.com");

// Get the string representation
assert_eq!(email.as_str(), "user@example.com");

// Parse from string
let email: Email = "user@example.com".parse()?;

Structs§

Email
An email address.

Enums§

EmailError
Error type for email validation.