use std::num::NonZeroU32;
#[derive(Debug, Clone, Copy, Default, serde::Serialize, serde::Deserialize)]
pub struct CompileOptions {
pub assert_message_annotations: AssertMessageAnnotations,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum AssertMessageAnnotations {
Off,
MaxBytes(NonZeroU32),
}
impl AssertMessageAnnotations {
pub const DEFAULT_MAX_BYTES: NonZeroU32 = NonZeroU32::new(120).expect("120 is non-zero");
#[must_use]
pub fn enabled(self) -> bool {
!matches!(self, Self::Off)
}
#[must_use]
pub fn max_bytes(self) -> u32 {
match self {
Self::Off => 0,
Self::MaxBytes(n) => n.get(),
}
}
#[must_use]
pub fn from_max_bytes(value: u32) -> Self {
match NonZeroU32::new(value) {
Some(n) => Self::MaxBytes(n),
None => Self::Off,
}
}
}
impl Default for AssertMessageAnnotations {
fn default() -> Self {
Self::MaxBytes(Self::DEFAULT_MAX_BYTES)
}
}
impl From<bool> for AssertMessageAnnotations {
fn from(enabled: bool) -> Self {
if enabled { Self::default() } else { Self::Off }
}
}