process_result_v1.rs (1724B)
1 //! Closed process-result and exit-code contract. 2 3 use std::process::ExitCode; 4 5 /// Exact stable RHI process result and exit-code inventory. 6 #[derive(Clone, Copy, Debug, PartialEq, Eq)] 7 pub enum RhiProcessResult { 8 Success, 9 UnexpectedInternal, 10 InputOrConfiguration, 11 ServiceOrDependencyUnavailable, 12 StateOrIdentityUnavailable, 13 OperationRejectedOrConflict, 14 DoctorRequiredCheckFailed, 15 } 16 17 impl RhiProcessResult { 18 /// Returns the exact stable process exit code. 19 #[must_use] 20 pub const fn exit_code_u8(self) -> u8 { 21 match self { 22 Self::Success => 0, 23 Self::UnexpectedInternal => 1, 24 Self::InputOrConfiguration => 2, 25 Self::ServiceOrDependencyUnavailable => 3, 26 Self::StateOrIdentityUnavailable => 4, 27 Self::OperationRejectedOrConflict => 5, 28 Self::DoctorRequiredCheckFailed => 6, 29 } 30 } 31 32 /// Returns the stable machine code. 33 #[must_use] 34 pub const fn code(self) -> &'static str { 35 match self { 36 Self::Success => "success", 37 Self::UnexpectedInternal => "unexpected_internal", 38 Self::InputOrConfiguration => "input_or_configuration", 39 Self::ServiceOrDependencyUnavailable => "service_or_dependency_unavailable", 40 Self::StateOrIdentityUnavailable => "state_or_identity_unavailable", 41 Self::OperationRejectedOrConflict => "operation_rejected_or_conflict", 42 Self::DoctorRequiredCheckFailed => "doctor_required_check_failed", 43 } 44 } 45 46 /// Returns the standard-library process exit value. 47 #[must_use] 48 pub fn exit_code(self) -> ExitCode { 49 ExitCode::from(self.exit_code_u8()) 50 } 51 }