envelopwd 0.1.0

A robust, lightweight library for parsing and validating email addresses and mailboxes with sqlx and lettre integration.
Documentation
// Copyright 2026 Thomas Zuyev

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

//     http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, thiserror::Error)]
pub enum Error {
    /// The local part (before the `@`) contains no characters.
    #[error("Local part is empty")]
    LocalPartEmpty,

    /// The domain part (after the `@`) contains no characters.
    #[error("Domain is empty")]
    DomainEmpty,

    /// The local part exceeds the maximum allowed length.
    /// Contains `(max_allowed, actual_provided)`.
    #[error("Local part is too long: max = {0}, provided = {1}")]
    LocalPartTooLong(usize, usize),

    /// The address contains a character that is not permitted by standard specifications.
    #[error("Invalid character")]
    InvalidCharacter,

    /// The address is missing the `@` separator.
    #[error("Missing separator character")]
    MissingSeparator,

    /// The domain part exceeds the maximum allowed length.
    /// Contains `(max_allowed, actual_provided)`.
    #[error("Domain part is too long: max = {0}, provided = {1}")]
    DomainTooLong(usize, usize),

    /// A sub-domain label (between dots) contains no characters.
    #[error("Sub-domain is empty")]
    SubDomainEmpty,

    /// A sub-domain label exceeds the maximum allowed length.
    /// Contains `(max_allowed, actual_provided)`.
    #[error("Sub-domain is too long: max = {0}, provided = {1}")]
    SubDomainTooLong(usize, usize),

    /// A literal or display name is missing its closing bracket (e.g., missing `>`).
    #[error("End bracket is missing")]
    MissingEndBracket,
}

pub type Result<T> = std::result::Result<T, Error>;