#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
#[expect(
clippy::enum_variant_names,
reason = "the shared Use prefix is the vendor's own: DecimalPoint_UsePeriod, \
DecimalPoint_UseComma. Stripping it to satisfy the lint would leave \
names that no longer match the reference a reader is holding."
)]
pub enum DecimalPointLocalizationOption {
UsePreference,
UseSystemSetting,
UsePeriod,
UseComma,
}
impl DecimalPointLocalizationOption {
pub const fn from_bits(bits: i32) -> Result<Self, i32> {
match bits {
1 => Ok(Self::UsePreference),
2 => Ok(Self::UseSystemSetting),
3 => Ok(Self::UsePeriod),
4 => Ok(Self::UseComma),
other => Err(other),
}
}
#[must_use]
pub const fn bits(self) -> i32 {
match self {
Self::UsePreference => 1,
Self::UseSystemSetting => 2,
Self::UsePeriod => 3,
Self::UseComma => 4,
}
}
}
#[cfg(test)]
mod tests {
use super::DecimalPointLocalizationOption;
#[test]
fn every_option_round_trips_through_the_engine_numbering() {
for option in [
DecimalPointLocalizationOption::UsePreference,
DecimalPointLocalizationOption::UseSystemSetting,
DecimalPointLocalizationOption::UsePeriod,
DecimalPointLocalizationOption::UseComma,
] {
assert_eq!(
DecimalPointLocalizationOption::from_bits(option.bits()),
Ok(option),
);
}
}
#[test]
fn zero_is_rejected_rather_than_silently_accepted() {
assert_eq!(DecimalPointLocalizationOption::from_bits(0), Err(0));
}
}