enumerated_latin 1.0.0

Encodes short strings as numeric values
Documentation
// SPDX-FileCopyrightText: 2025 Slatian
//
// SPDX-License-Identifier: LGPL-3.0-only

/// Trait for implementing number to character behavior on.
///
/// It is custom made for the usecases:
/// * all lowercase
/// * all uppercase
/// * titlecase
pub trait DecodingStyle {
	fn number_to_letter(to_decode: u8, is_first: bool) -> Option<char>;
}

pub struct AllLowercase();

pub struct AllUppercase();

pub struct Titlecase();

impl DecodingStyle for AllLowercase {
	#[inline(always)]
	fn number_to_letter(to_decode: u8, _is_first: bool) -> Option<char> {
		match to_decode {
			0..=25 => Some((b'a' + to_decode) as char),
			_ => None,
		}
	}
}

impl DecodingStyle for AllUppercase {
	#[inline(always)]
	fn number_to_letter(to_decode: u8, _is_first: bool) -> Option<char> {
		match to_decode {
			0..=25 => Some((b'A' + to_decode) as char),
			_ => None,
		}
	}
}

impl DecodingStyle for Titlecase {
	#[inline(always)]
	fn number_to_letter(to_decode: u8, is_first: bool) -> Option<char> {
		match to_decode {
			0..=25 if is_first => Some((b'A' + to_decode) as char),
			0..=25 => Some((b'a' + to_decode) as char),
			_ => None,
		}
	}
}