behavior_actors/
termination.rs1use behavior::{InterpretationProgress, ItemSettlement, finish_item, prepare_item};
4
5use behavior::Address;
6
7pub type TerminalOutcome<A> = Result<Exit<A>, Crash>;
14
15#[derive(Debug, Clone, Copy, PartialEq, Eq)]
17pub enum Exit<A: Address> {
18 Normal,
20 Collected,
22 LinkDied(A),
24 SupervisionFailed(SupervisionFailureReason),
26}
27
28#[derive(Debug, Clone, Copy, PartialEq, Eq)]
30pub enum SupervisionFailureReason {
31 RestartDenied(RestartDenial),
32 StableChildStopped,
33 StableChildCreationRejected(behavior::CreationRejection),
34 WorkerFactoryRejected,
35 WorkerCreationRejected(behavior::CreationRejection),
36}
37
38#[derive(Debug, Clone, Copy, PartialEq, Eq)]
40pub enum RestartDenial {
41 BudgetExceeded {
42 restarts_in_window: usize,
43 replacements_requested: usize,
44 maximum_restarts: u32,
45 },
46 ReleaseRejected(crate::RestartReleaseFailure),
48 AttemptSequenceExhausted,
50 TimerGenerationExhausted,
52 TimerIdentityExhausted,
54}
55
56#[derive(Debug, Clone, Copy, PartialEq, Eq)]
58pub enum Crash {
59 Failed,
60 EnvironmentFailed,
61 CapabilityFailed,
64 Panicked,
65 Cancelled,
66}
67
68#[derive(Debug, Clone, Copy, PartialEq, Eq)]
77pub struct ReportTerminalOutcome<A: Address> {
78 pub outcome: TerminalOutcome<A>,
79}
80
81impl<A: Address> ReportTerminalOutcome<A> {
82 #[must_use]
83 pub const fn new(outcome: TerminalOutcome<A>) -> Self {
84 Self { outcome }
85 }
86}
87
88impl<A: Address> behavior::InterpreterRequest for ReportTerminalOutcome<A> {
89 type ReturnToEmitter = behavior::NoReturnToEmitter;
90 type LogicalProtocols = behavior::NoBirthProtocols;
91}
92
93impl<A> behavior::ActionItem for ReportTerminalOutcome<A>
94where
95 A: Address + Send,
96{
97 type Custody = (Option<Self>, Option<Self::Reply>);
98 type Input<'a>
99 = &'a mut Option<Self>
100 where
101 Self: 'a;
102 type Reply = ItemSettlement<Self, Self::Accepted, Self::Rejection, Self::Prerequisite>;
103
104 fn prepare_interpretation(
105 progress: &mut Option<InterpretationProgress<Self, Self::Custody, Self::Reply>>,
106 ) {
107 prepare_item::<Self>(progress);
108 }
109
110 fn interpretation_input<'a>(
111 custody: &'a mut Self::Custody,
112 ) -> Option<(Self::Input<'a>, &'a mut Option<Self::Reply>)>
113 where
114 Self: 'a,
115 {
116 match custody {
117 (input @ Some(_), received @ None) => Some((input, received)),
118 _ => None,
119 }
120 }
121
122 fn finish_interpretation(
123 progress: &mut Option<InterpretationProgress<Self, Self::Custody, Self::Reply>>,
124 ) {
125 finish_item::<Self>(progress);
126 }
127
128 type Accepted = ();
129 type Rejection = behavior::Never;
130 type Prerequisite = behavior::Never;
131}