wasmflow_component/
signals.rs1use std::str::FromStr;
2
3#[allow(missing_debug_implementations, missing_copy_implementations)]
4#[must_use]
5pub enum OutputSignal {
7 Output,
9 OutputDone,
11 Done,
13}
14
15impl OutputSignal {
16 #[must_use]
17 #[doc(hidden)]
18 pub fn as_str(&self) -> &'static str {
19 match self {
20 OutputSignal::Output => "1",
21 OutputSignal::OutputDone => "2",
22 OutputSignal::Done => "3",
23 }
24 }
25}
26
27impl FromStr for OutputSignal {
28 type Err = ();
29
30 fn from_str(s: &str) -> Result<Self, Self::Err> {
31 let result = match s {
32 "1" => OutputSignal::Output,
33 "2" => OutputSignal::OutputDone,
34 "3" => OutputSignal::Done,
35 _ => return Err(()),
36 };
37 Ok(result)
38 }
39}
40
41#[allow(missing_debug_implementations, missing_copy_implementations)]
42#[must_use]
43pub enum HostCommand {
45 Output,
47 LinkCall,
49 Log,
51}
52
53impl HostCommand {
54 #[must_use]
55 #[doc(hidden)]
56 pub fn as_str(&self) -> &'static str {
57 match self {
58 HostCommand::Output => "0",
59 HostCommand::LinkCall => "1",
60 HostCommand::Log => "2",
61 }
62 }
63}
64
65impl FromStr for HostCommand {
66 type Err = ();
67
68 fn from_str(s: &str) -> Result<Self, Self::Err> {
69 let result = match s {
70 "0" => HostCommand::Output,
71 "1" => HostCommand::LinkCall,
72 "2" => HostCommand::Log,
73 _ => return Err(()),
74 };
75 Ok(result)
76 }
77}
78
79#[allow(missing_debug_implementations, missing_copy_implementations)]
80#[must_use]
81pub enum LogLevel {
83 Info,
85 Error,
87 Warn,
89 Debug,
91 Trace,
93 Mark,
95}
96
97impl LogLevel {
98 #[must_use]
99 #[doc(hidden)]
100 pub fn as_str(&self) -> &'static str {
101 match self {
102 LogLevel::Info => "0",
103 LogLevel::Error => "1",
104 LogLevel::Warn => "2",
105 LogLevel::Debug => "3",
106 LogLevel::Trace => "4",
107 LogLevel::Mark => "5",
108 }
109 }
110}
111
112impl FromStr for LogLevel {
113 type Err = ();
114
115 fn from_str(s: &str) -> Result<Self, Self::Err> {
116 let result = match s {
117 "0" => LogLevel::Info,
118 "1" => LogLevel::Error,
119 "2" => LogLevel::Warn,
120 "3" => LogLevel::Debug,
121 "4" => LogLevel::Trace,
122 "5" => LogLevel::Mark,
123 _ => return Err(()),
124 };
125 Ok(result)
126 }
127}