Skip to main content

atomic_snowflake/error/
impl.rs

1use super::*;
2
3/// Formats [`IdError`] as a human-readable diagnostic message.
4impl fmt::Display for IdError {
5    /// Writes the error description to `f`.
6    ///
7    /// # Arguments
8    ///
9    /// - `&mut fmt::Formatter<'_>` - The destination formatter.
10    ///
11    /// # Returns
12    ///
13    /// - `fmt::Result` - Formatting outcome.
14    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
15        let message: &str = match self {
16            Self::NodeIdOutOfRange => ERR_NODE_ID_OUT_OF_RANGE,
17            Self::InvalidUlidLength => ERR_INVALID_ULID_LENGTH,
18            Self::InvalidUlidCharacter => ERR_INVALID_ULID_CHAR,
19            Self::UlidOverflow => ERR_ULID_OVERFLOW,
20            Self::InvalidUuidFormat => ERR_INVALID_UUID_FORMAT,
21            Self::InvalidSnowflakeString => ERR_INVALID_SNOWFLAKE_STR,
22        };
23        f.write_str(message)
24    }
25}
26
27/// Marks [`IdError`] as a standard error type.
28impl Error for IdError {}