1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use crate::{
abi::TypeAbi,
api::{EndpointFinishApi, ManagedTypeApi},
types::BoxedBytes,
EndpointResult,
};
use alloc::string::String;
#[derive(PartialEq, Debug, Clone, Copy)]
pub enum OperationCompletionStatus {
Completed,
InterruptedBeforeOutOfGas,
}
impl OperationCompletionStatus {
pub fn output_bytes(&self) -> &'static [u8] {
match self {
OperationCompletionStatus::Completed => b"completed",
OperationCompletionStatus::InterruptedBeforeOutOfGas => b"interrupted",
}
}
pub fn is_completed(&self) -> bool {
matches!(self, OperationCompletionStatus::Completed)
}
pub fn is_interrupted(&self) -> bool {
matches!(self, OperationCompletionStatus::InterruptedBeforeOutOfGas)
}
}
impl EndpointResult for OperationCompletionStatus {
type DecodeAs = BoxedBytes;
#[inline]
fn finish<FA>(&self, api: FA)
where
FA: ManagedTypeApi + EndpointFinishApi + Clone + 'static,
{
self.output_bytes().finish(api);
}
}
impl TypeAbi for OperationCompletionStatus {
fn type_name() -> String {
String::from("OperationCompletionStatus")
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_operation_completion_status_is() {
assert!(OperationCompletionStatus::Completed.is_completed());
assert!(!OperationCompletionStatus::Completed.is_interrupted());
assert!(!OperationCompletionStatus::InterruptedBeforeOutOfGas.is_completed());
assert!(OperationCompletionStatus::InterruptedBeforeOutOfGas.is_interrupted());
}
}