alphanumeric-stepper 0.1.0

A reversible alphanumeric sequence codec for compact serial codes like 000..999, A00..Z99, AA0..ZZ9, and AAA..ZZZ.
Documentation
use core::fmt::{self, Display, Formatter};
#[cfg(feature = "std")]
use std::error::Error;

#[derive(Debug, Clone)]
pub enum AlphanumericStepperBuildError {
    InvalidWidth,
}

impl Display for AlphanumericStepperBuildError {
    #[inline]
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        match self {
            Self::InvalidWidth => f.write_str("invalid width"),
        }
    }
}

#[cfg(feature = "std")]
impl Error for AlphanumericStepperBuildError {}

#[derive(Debug, Clone)]
pub enum AlphanumericStepperEncodeError {
    NumberOutOfRange,
}

impl Display for AlphanumericStepperEncodeError {
    #[inline]
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        match self {
            Self::NumberOutOfRange => f.write_str("number out of range"),
        }
    }
}

#[cfg(feature = "std")]
impl Error for AlphanumericStepperEncodeError {}

#[derive(Debug, Clone)]
pub enum AlphanumericStepperDecodeError {
    InvalidLength,
    InvalidCharacter,
}

impl Display for AlphanumericStepperDecodeError {
    #[inline]
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        match self {
            Self::InvalidLength => f.write_str("invalid length"),
            Self::InvalidCharacter => f.write_str("invalid character"),
        }
    }
}

#[cfg(feature = "std")]
impl Error for AlphanumericStepperDecodeError {}