#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
#[non_exhaustive]
pub enum ResultRecordingOption {
Disabled = 0,
#[default]
Enabled = 1,
EnabledAndOverrideSequenceSetting = 2,
}
impl ResultRecordingOption {
pub const fn from_bits(raw: i32) -> Result<Self, crate::Error> {
match raw {
0 => Ok(Self::Disabled),
1 => Ok(Self::Enabled),
2 => Ok(Self::EnabledAndOverrideSequenceSetting),
_ => Err(crate::Error::UnexpectedType {
expected: "a known result recording option (0, 1 or 2)",
actual: "a value this build does not name",
}),
}
}
}
#[cfg(test)]
mod tests {
use super::ResultRecordingOption;
#[test]
fn a_step_records_its_result_unless_told_otherwise() {
assert_eq!(
ResultRecordingOption::default(),
ResultRecordingOption::Enabled
);
}
#[test]
fn every_option_round_trips_through_its_raw_value() {
for option in [
ResultRecordingOption::Disabled,
ResultRecordingOption::Enabled,
ResultRecordingOption::EnabledAndOverrideSequenceSetting,
] {
assert_eq!(
ResultRecordingOption::from_bits(option as i32).ok(),
Some(option)
);
}
}
#[test]
fn an_unknown_value_is_reported_rather_than_guessed() {
assert!(ResultRecordingOption::from_bits(7).is_err());
assert!(ResultRecordingOption::from_bits(-1).is_err());
}
}