aws_durable_execution_sdk/
operation.rs1use std::fmt;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7#[non_exhaustive]
8pub enum OperationKind {
9 Step,
11 Wait,
13 Context,
16 Callback,
18 ChainedInvoke,
20 Execution,
22}
23
24impl OperationKind {
25 #[must_use]
28 pub fn wire_str(self) -> &'static str {
29 match self {
30 Self::Step => "STEP",
31 Self::Wait => "WAIT",
32 Self::Context => "CONTEXT",
33 Self::Callback => "CALLBACK",
34 Self::ChainedInvoke => "CHAINED_INVOKE",
35 Self::Execution => "EXECUTION",
36 }
37 }
38
39 pub(crate) fn from_wire(t: &aws_sdk_lambda::types::OperationType) -> Option<Self> {
42 use aws_sdk_lambda::types::OperationType;
43 match t {
44 OperationType::Step => Some(Self::Step),
45 OperationType::Wait => Some(Self::Wait),
46 OperationType::Context => Some(Self::Context),
47 OperationType::Callback => Some(Self::Callback),
48 OperationType::ChainedInvoke => Some(Self::ChainedInvoke),
49 OperationType::Execution => Some(Self::Execution),
50 _ => None,
51 }
52 }
53}
54
55impl fmt::Display for OperationKind {
56 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
57 f.write_str(match self {
58 Self::Step => "Step",
59 Self::Wait => "Wait",
60 Self::Context => "Context",
61 Self::Callback => "Callback",
62 Self::ChainedInvoke => "ChainedInvoke",
63 Self::Execution => "Execution",
64 })
65 }
66}
67
68#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
73#[non_exhaustive]
74pub enum OperationStatus {
75 Started,
77 Pending,
79 Ready,
81 Succeeded,
83 Failed,
85 Cancelled,
87 TimedOut,
89 Stopped,
91}
92
93impl OperationStatus {
94 #[must_use]
97 pub fn wire_str(self) -> &'static str {
98 match self {
99 Self::Started => "STARTED",
100 Self::Pending => "PENDING",
101 Self::Ready => "READY",
102 Self::Succeeded => "SUCCEEDED",
103 Self::Failed => "FAILED",
104 Self::Cancelled => "CANCELLED",
105 Self::TimedOut => "TIMED_OUT",
106 Self::Stopped => "STOPPED",
107 }
108 }
109}
110
111impl fmt::Display for OperationStatus {
112 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
113 f.write_str(match self {
114 Self::Started => "Started",
115 Self::Pending => "Pending",
116 Self::Ready => "Ready",
117 Self::Succeeded => "Succeeded",
118 Self::Failed => "Failed",
119 Self::Cancelled => "Cancelled",
120 Self::TimedOut => "TimedOut",
121 Self::Stopped => "Stopped",
122 })
123 }
124}
125
126#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
128#[non_exhaustive]
129pub enum InvocationStatus {
130 Succeeded,
132 Failed,
134 Pending,
137 Retrying,
139}
140
141impl InvocationStatus {
142 #[must_use]
145 pub fn wire_str(self) -> &'static str {
146 match self {
147 Self::Succeeded => "SUCCEEDED",
148 Self::Failed => "FAILED",
149 Self::Pending => "PENDING",
150 Self::Retrying => "RETRYING",
151 }
152 }
153}
154
155impl fmt::Display for InvocationStatus {
156 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
157 f.write_str(match self {
158 Self::Succeeded => "Succeeded",
159 Self::Failed => "Failed",
160 Self::Pending => "Pending",
161 Self::Retrying => "Retrying",
162 })
163 }
164}
165
166#[cfg(test)]
167mod tests {
168 use super::{InvocationStatus, OperationKind, OperationStatus};
169
170 #[test]
173 fn invocation_status_displays_variant_names() {
174 let all = [
175 InvocationStatus::Succeeded,
176 InvocationStatus::Failed,
177 InvocationStatus::Pending,
178 InvocationStatus::Retrying,
179 ];
180 let shown: Vec<String> = all.iter().map(ToString::to_string).collect();
181 assert_eq!(shown, ["Succeeded", "Failed", "Pending", "Retrying"]);
182 let wire: Vec<&str> = all.iter().map(|s| s.wire_str()).collect();
183 assert_eq!(wire, ["SUCCEEDED", "FAILED", "PENDING", "RETRYING"]);
184 }
185
186 const KINDS: [OperationKind; 6] = [
187 OperationKind::Step,
188 OperationKind::Wait,
189 OperationKind::Context,
190 OperationKind::Callback,
191 OperationKind::ChainedInvoke,
192 OperationKind::Execution,
193 ];
194
195 const STATUSES: [OperationStatus; 8] = [
196 OperationStatus::Started,
197 OperationStatus::Pending,
198 OperationStatus::Ready,
199 OperationStatus::Succeeded,
200 OperationStatus::Failed,
201 OperationStatus::Cancelled,
202 OperationStatus::TimedOut,
203 OperationStatus::Stopped,
204 ];
205
206 #[test]
207 fn operation_enums_display_as_variant_names() {
208 let kinds: Vec<String> = KINDS.iter().map(ToString::to_string).collect();
209 assert_eq!(
210 kinds,
211 [
212 "Step",
213 "Wait",
214 "Context",
215 "Callback",
216 "ChainedInvoke",
217 "Execution"
218 ]
219 );
220 let statuses: Vec<String> = STATUSES.iter().map(ToString::to_string).collect();
221 assert_eq!(
222 statuses,
223 [
224 "Started",
225 "Pending",
226 "Ready",
227 "Succeeded",
228 "Failed",
229 "Cancelled",
230 "TimedOut",
231 "Stopped"
232 ]
233 );
234 }
235
236 #[test]
237 fn operation_enums_wire_spelling() {
238 let kinds: Vec<&str> = KINDS.iter().map(|k| k.wire_str()).collect();
239 assert_eq!(
240 kinds,
241 [
242 "STEP",
243 "WAIT",
244 "CONTEXT",
245 "CALLBACK",
246 "CHAINED_INVOKE",
247 "EXECUTION"
248 ]
249 );
250 let statuses: Vec<&str> = STATUSES.iter().map(|s| s.wire_str()).collect();
251 assert_eq!(
252 statuses,
253 [
254 "STARTED",
255 "PENDING",
256 "READY",
257 "SUCCEEDED",
258 "FAILED",
259 "CANCELLED",
260 "TIMED_OUT",
261 "STOPPED"
262 ]
263 );
264 }
265}