pub enum ExitReason {
Normal,
Shutdown,
ShutdownReason(String),
Killed,
Error(String),
}Expand description
The reason a process exited.
Exit reasons determine how linked processes and supervisors respond to process termination.
§Normal vs Abnormal Exits
-
Normal exits (
ExitReason::Normal,ExitReason::Shutdown,ExitReason::ShutdownReason): Do not trigger restarts forTransientchildren in supervisors. Links withtrap_exit = falsedo not propagate. -
Abnormal exits (
ExitReason::Killed,ExitReason::Error): Trigger restarts and propagate through links.
§Examples
use starlang_core::ExitReason;
let reason = ExitReason::Normal;
assert!(reason.is_normal());
let reason = ExitReason::Error("connection lost".to_string());
assert!(!reason.is_normal());Variants§
Normal
Process completed successfully.
This is the standard exit reason when a process finishes its work without errors.
Shutdown
Process was asked to shut down.
Used when a supervisor or other controller requests graceful termination.
ShutdownReason(String)
Process was asked to shut down with a specific reason.
Similar to Shutdown but includes additional context.
Killed
Process was forcefully terminated.
Used with Process::exit(pid, ExitReason::Killed) for unconditional
termination that cannot be trapped.
Error(String)
Process terminated due to an error.
This is an abnormal exit that will trigger supervisor restarts and propagate through links.
Implementations§
Source§impl ExitReason
impl ExitReason
Sourcepub fn is_normal(&self) -> bool
pub fn is_normal(&self) -> bool
Returns true if this is a normal exit reason.
Normal exits include Normal, Shutdown, and ShutdownReason.
These do not trigger supervisor restarts for Transient children.
§Examples
use starlang_core::ExitReason;
assert!(ExitReason::Normal.is_normal());
assert!(ExitReason::Shutdown.is_normal());
assert!(ExitReason::ShutdownReason("done".into()).is_normal());
assert!(!ExitReason::Killed.is_normal());
assert!(!ExitReason::Error("oops".into()).is_normal());Sourcepub fn is_abnormal(&self) -> bool
pub fn is_abnormal(&self) -> bool
Returns true if this is an abnormal exit reason.
Abnormal exits include Killed and Error. These trigger supervisor
restarts and propagate through links to non-trapping processes.
Sourcepub fn is_killed(&self) -> bool
pub fn is_killed(&self) -> bool
Returns true if this is the Killed variant.
The Killed reason is special: it cannot be trapped and always
terminates the target process.
Sourcepub fn error(msg: impl Display) -> ExitReason
pub fn error(msg: impl Display) -> ExitReason
Creates an error exit reason from any displayable type.
§Examples
use starlang_core::ExitReason;
let reason = ExitReason::error("something went wrong");
assert_eq!(reason, ExitReason::Error("something went wrong".to_string()));Sourcepub fn shutdown(msg: impl Display) -> ExitReason
pub fn shutdown(msg: impl Display) -> ExitReason
Creates a shutdown exit reason with a message.
§Examples
use starlang_core::ExitReason;
let reason = ExitReason::shutdown("maintenance");
assert!(reason.is_normal());Trait Implementations§
Source§impl Clone for ExitReason
impl Clone for ExitReason
Source§fn clone(&self) -> ExitReason
fn clone(&self) -> ExitReason
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ExitReason
impl Debug for ExitReason
Source§impl Default for ExitReason
impl Default for ExitReason
Source§fn default() -> ExitReason
fn default() -> ExitReason
Source§impl<'de> Deserialize<'de> for ExitReason
impl<'de> Deserialize<'de> for ExitReason
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<ExitReason, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<ExitReason, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Display for ExitReason
impl Display for ExitReason
impl Eq for ExitReason
Source§impl From<&str> for ExitReason
impl From<&str> for ExitReason
Source§fn from(s: &str) -> ExitReason
fn from(s: &str) -> ExitReason
Source§impl From<String> for ExitReason
impl From<String> for ExitReason
Source§fn from(s: String) -> ExitReason
fn from(s: String) -> ExitReason
Source§impl PartialEq for ExitReason
impl PartialEq for ExitReason
Source§fn eq(&self, other: &ExitReason) -> bool
fn eq(&self, other: &ExitReason) -> bool
self and other values to be equal, and is used by ==.