o192 0.2.2

ORION-192: ordered, resilient, independent, URL-safe 192-bit IDs for distributed systems.
Documentation
//! Error type for the ORION-192 implementation.

use core::fmt;

/// All errors produced by this crate.
///
/// The variant is the stable, machine-readable tag intended for
/// programmatic handling; the [`fmt::Display`] impl renders a human-friendly
/// message that may evolve between releases.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum OrionIdError {
    /// Input string or buffer has the wrong size for a canonical
    /// ORION-192 identifier.
    InvalidLength,
    /// Input string contains a character outside the sortable64 alphabet.
    InvalidCharacter,
    /// An option value is outside its accepted range.
    InvalidOption(&'static str),
    /// `relative_ms` exceeds the 48-bit field — choose a later epoch.
    TimestampOverflow,
    /// The 20-bit counter overflowed without the synthetic tick mechanism
    /// being able to advance. This should not happen in practice.
    CounterOverflow,
    /// The operating-system CSPRNG failed.
    RandomFailure,
}

impl fmt::Display for OrionIdError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::InvalidLength => f.write_str("ORION-192 id must be 32 characters"),
            Self::InvalidCharacter => {
                f.write_str("ORION-192 id contains a character outside the sortable64 alphabet")
            }
            Self::InvalidOption(name) => write!(f, "invalid option: {name}"),
            Self::TimestampOverflow => {
                f.write_str("ORION-192 timestamp overflow: choose a later epoch_ms")
            }
            Self::CounterOverflow => f.write_str("ORION-192 counter overflow"),
            Self::RandomFailure => f.write_str("operating-system CSPRNG failed"),
        }
    }
}

impl std::error::Error for OrionIdError {}