rusm_otp/exit.rs
1/// Why a process terminated — carried to linked and monitoring processes.
2#[derive(Debug, Clone, Copy, PartialEq, Eq)]
3pub enum ExitReason {
4 /// Ran to completion, or was asked to stop cleanly. Does **not** propagate
5 /// down links (linked peers survive unless they trap exits).
6 Normal,
7 /// Stopped by [`kill`](crate::Runtime::kill) or a link cascade.
8 Killed,
9 /// The body panicked — Erlang's "let it crash".
10 Crashed,
11 /// Reported by a monitor when its target was already gone (Erlang's `noproc`).
12 NoProc,
13}
14
15impl ExitReason {
16 /// Whether this reason propagates death down links — everything but
17 /// [`Normal`](ExitReason::Normal), matching Erlang's exit-signal rules.
18 pub fn is_abnormal(self) -> bool {
19 !matches!(self, ExitReason::Normal)
20 }
21}
22
23/// Identifies a monitor set up with [`monitor`](crate::Runtime::monitor); echoed
24/// back in the resulting [`Received::Down`](crate::Received::Down) so a watcher
25/// can tell its monitors apart.
26#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
27pub struct MonitorRef(pub(crate) u64);
28
29impl MonitorRef {
30 pub fn raw(self) -> u64 {
31 self.0
32 }
33}
34
35#[cfg(test)]
36mod tests {
37 use super::*;
38
39 #[test]
40 fn only_normal_is_not_abnormal() {
41 assert!(!ExitReason::Normal.is_abnormal());
42 assert!(ExitReason::Killed.is_abnormal());
43 assert!(ExitReason::Crashed.is_abnormal());
44 assert!(ExitReason::NoProc.is_abnormal());
45 }
46
47 #[test]
48 fn monitor_ref_exposes_its_raw_id() {
49 assert_eq!(MonitorRef(7).raw(), 7);
50 }
51}