#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum ApplicationLicense {
Unspecified,
OperatorInterface,
CustomEditor,
SequenceEditor,
}
impl ApplicationLicense {
pub const fn from_bits(bits: i32) -> Result<Self, i32> {
match bits {
0 => Ok(Self::Unspecified),
100 => Ok(Self::OperatorInterface),
200 => Ok(Self::CustomEditor),
300 => Ok(Self::SequenceEditor),
unknown => Err(unknown),
}
}
#[must_use]
pub const fn bits(self) -> i32 {
match self {
Self::Unspecified => 0,
Self::OperatorInterface => 100,
Self::CustomEditor => 200,
Self::SequenceEditor => 300,
}
}
}
#[cfg(test)]
mod tests {
use super::ApplicationLicense;
#[test]
fn every_documented_value_round_trips() {
for kind in [
ApplicationLicense::Unspecified,
ApplicationLicense::OperatorInterface,
ApplicationLicense::CustomEditor,
ApplicationLicense::SequenceEditor,
] {
assert_eq!(ApplicationLicense::from_bits(kind.bits()), Ok(kind));
}
}
#[test]
fn the_values_are_not_ordinals() {
assert_eq!(ApplicationLicense::OperatorInterface.bits(), 100);
assert_eq!(ApplicationLicense::SequenceEditor.bits(), 300);
assert_eq!(ApplicationLicense::from_bits(1), Err(1));
}
}