use crate::{
Report,
fmt::r#override::{AtomicOverride, AtomicPreference},
};
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Default)]
pub enum Charset {
#[default]
Utf8,
Ascii,
}
impl Charset {
pub(super) fn load() -> Self {
CHARSET_OVERRIDE.load()
}
}
impl AtomicPreference for Charset {
fn from_u8(value: u8) -> Self {
match value {
0x00 => Self::Ascii,
0x01 => Self::Utf8,
_ => Self::default(),
}
}
fn into_u8(self) -> u8 {
match self {
Self::Ascii => 0x00,
Self::Utf8 => 0x01,
}
}
}
static CHARSET_OVERRIDE: AtomicOverride<Charset> = AtomicOverride::new();
impl Report<()> {
#[cfg_attr(doc, doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/snapshots/doc/fmt__charset_utf8.snap")))]
#[cfg_attr(doc, doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/snapshots/doc/fmt__charset_ascii.snap")))]
pub fn set_charset(charset: Charset) {
CHARSET_OVERRIDE.store(charset);
}
}