#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(i32)]
pub enum UIMessageCode {
BreakOnUserRequest = 1,
BreakOnBreakpoint = 2,
BreakOnRunTimeError = 3,
Trace = 4,
TerminatingExecution = 5,
AbortingExecution = 6,
KillingExecutionThreads = 7,
EndExecution = 8,
ShutDownComplete = 9,
StartExecution = 10,
ProgressPercent = 11,
ProgressText = 12,
StartInteractiveExecution = 13,
EndInteractiveExecution = 14,
TerminatingInteractiveExecution = 15,
TerminationCanceled = 16,
ResumeFromBreak = 17,
StartFileExecution = 18,
EndFileExecution = 19,
ShutDownCanceled = 20,
LocalizationSettingChanged = 21,
OpenWindows = 22,
TileWindows = 23,
CascadeWindows = 24,
ReportChanged = 25,
CloseWindows = 26,
RefreshWindows = 27,
ClientFileChanged = 28,
DisplayReport = 29,
ModelStateInitializing = 30,
ModelStateWaiting = 31,
ModelStateIdentified = 32,
ModelStateBeginTesting = 33,
ModelStateTestingComplete = 34,
ModelStatePostProcessingComplete = 35,
ModelStateEnabledStateSet = 36,
ReportLocationChanged = 37,
GotoLocation = 38,
PushUndoItem = 39,
OutputMessages = 40,
TypePaletteFileListChanged = 41,
NonTerminatableThreadsArePreventingTermination = 42,
ModelStatePostProcessing = 43,
ReportCollectionChanged = 44,
RuntimeError = 45,
}
impl UIMessageCode {
pub const ALL: [Self; 45] = [
Self::BreakOnUserRequest,
Self::BreakOnBreakpoint,
Self::BreakOnRunTimeError,
Self::Trace,
Self::TerminatingExecution,
Self::AbortingExecution,
Self::KillingExecutionThreads,
Self::EndExecution,
Self::ShutDownComplete,
Self::StartExecution,
Self::ProgressPercent,
Self::ProgressText,
Self::StartInteractiveExecution,
Self::EndInteractiveExecution,
Self::TerminatingInteractiveExecution,
Self::TerminationCanceled,
Self::ResumeFromBreak,
Self::StartFileExecution,
Self::EndFileExecution,
Self::ShutDownCanceled,
Self::LocalizationSettingChanged,
Self::OpenWindows,
Self::TileWindows,
Self::CascadeWindows,
Self::ReportChanged,
Self::CloseWindows,
Self::RefreshWindows,
Self::ClientFileChanged,
Self::DisplayReport,
Self::ModelStateInitializing,
Self::ModelStateWaiting,
Self::ModelStateIdentified,
Self::ModelStateBeginTesting,
Self::ModelStateTestingComplete,
Self::ModelStatePostProcessingComplete,
Self::ModelStateEnabledStateSet,
Self::ReportLocationChanged,
Self::GotoLocation,
Self::PushUndoItem,
Self::OutputMessages,
Self::TypePaletteFileListChanged,
Self::NonTerminatableThreadsArePreventingTermination,
Self::ModelStatePostProcessing,
Self::ReportCollectionChanged,
Self::RuntimeError,
];
pub const USER_MESSAGE_BASE: i32 = 10000;
#[must_use]
pub const fn bits(self) -> i32 {
self as i32
}
#[must_use]
pub const fn is_user_message(raw: i32) -> bool {
raw >= Self::USER_MESSAGE_BASE
}
pub const fn from_bits(raw: i32) -> Result<Self, i32> {
Ok(match raw {
1 => Self::BreakOnUserRequest,
2 => Self::BreakOnBreakpoint,
3 => Self::BreakOnRunTimeError,
4 => Self::Trace,
5 => Self::TerminatingExecution,
6 => Self::AbortingExecution,
7 => Self::KillingExecutionThreads,
8 => Self::EndExecution,
9 => Self::ShutDownComplete,
10 => Self::StartExecution,
11 => Self::ProgressPercent,
12 => Self::ProgressText,
13 => Self::StartInteractiveExecution,
14 => Self::EndInteractiveExecution,
15 => Self::TerminatingInteractiveExecution,
16 => Self::TerminationCanceled,
17 => Self::ResumeFromBreak,
18 => Self::StartFileExecution,
19 => Self::EndFileExecution,
20 => Self::ShutDownCanceled,
21 => Self::LocalizationSettingChanged,
22 => Self::OpenWindows,
23 => Self::TileWindows,
24 => Self::CascadeWindows,
25 => Self::ReportChanged,
26 => Self::CloseWindows,
27 => Self::RefreshWindows,
28 => Self::ClientFileChanged,
29 => Self::DisplayReport,
30 => Self::ModelStateInitializing,
31 => Self::ModelStateWaiting,
32 => Self::ModelStateIdentified,
33 => Self::ModelStateBeginTesting,
34 => Self::ModelStateTestingComplete,
35 => Self::ModelStatePostProcessingComplete,
36 => Self::ModelStateEnabledStateSet,
37 => Self::ReportLocationChanged,
38 => Self::GotoLocation,
39 => Self::PushUndoItem,
40 => Self::OutputMessages,
41 => Self::TypePaletteFileListChanged,
42 => Self::NonTerminatableThreadsArePreventingTermination,
43 => Self::ModelStatePostProcessing,
44 => Self::ReportCollectionChanged,
45 => Self::RuntimeError,
other => return Err(other),
})
}
}
#[cfg(test)]
mod tests {
use super::UIMessageCode;
#[test]
fn every_code_round_trips() {
for code in UIMessageCode::ALL {
assert_eq!(UIMessageCode::from_bits(code.bits()), Ok(code));
}
}
#[test]
fn engine_codes_sit_below_the_user_range() {
for code in UIMessageCode::ALL {
assert!(
!UIMessageCode::is_user_message(code.bits()),
"{code:?} collides with the user range"
);
}
}
#[test]
fn a_sequence_posted_code_is_recognized() {
assert!(UIMessageCode::is_user_message(
UIMessageCode::USER_MESSAGE_BASE
));
assert!(UIMessageCode::is_user_message(
UIMessageCode::USER_MESSAGE_BASE + 1
));
assert_eq!(
UIMessageCode::from_bits(UIMessageCode::USER_MESSAGE_BASE + 1),
Err(10001)
);
}
#[test]
fn shutdown_complete_keeps_the_value_the_watchdog_relies_on() {
assert_eq!(UIMessageCode::ShutDownComplete.bits(), 9);
}
}