joyful 0.1.0

Generate delightful, random word combinations - Rust port of the joyful TypeScript library
Documentation
//! Error types for the joyful library.
//!
//! This module defines the validation errors that can occur when generating
//! word combinations with invalid or impossible-to-satisfy constraints.

/// Validation errors that can occur when generating word combinations.
///
/// These errors indicate that the provided [`Options`](crate::Options) are either
/// invalid or describe constraints that cannot be satisfied.
#[derive(Debug, Hash, PartialEq)]
pub enum ValidationError {
    /// The requested number of segments exceeds the maximum allowed (300).
    ///
    /// This limit exists because the word lists contain a finite number of unique words,
    /// and the generator guarantees word uniqueness within each result.
    TooManySegments,

    /// The requested number of segments is less than the minimum required (2).
    ///
    /// At least 2 segments are required: one prefix and one additional word.
    TooFewSegments,

    /// The maximum length constraint cannot be satisfied with the requested number of segments.
    ///
    /// This occurs when the `max_length` is too small to accommodate the minimum
    /// possible word combinations for the specified number of segments.
    LengthConstraintImpossible,

    /// An invalid value was provided for a configuration option.
    ///
    /// The contained `usize` is the invalid value that was provided.
    InvalidValue(usize),
}

impl std::fmt::Display for ValidationError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::TooManySegments => write!(f, "Too many segments"),
            Self::TooFewSegments => write!(f, "Too few segments. At least 2 required"),
            Self::LengthConstraintImpossible => {
                write!(
                    f,
                    "Max length constraint cannot be satisfied with requested segments"
                )
            }
            Self::InvalidValue(v) => write!(f, "Invalid value: {}", v),
        }
    }
}