1use std::str::FromStr;
2
3use strum::EnumIter;
4pub use strum::IntoEnumIterator;
5
6pub mod host_exports {
8 pub const INIT: &str = "__init_buffers";
10 pub const SEND: &str = "__send";
12 pub const LOG: &str = "__console_log";
14 pub const OP_LIST: &str = "__op_list";
16}
17
18#[derive(Debug, Copy, Clone, EnumIter)]
20#[allow(missing_docs)]
21pub enum HostExports {
22 Init,
23 Send,
24 Log,
25 OpList,
26}
27
28impl FromStr for HostExports {
29 type Err = ();
30
31 fn from_str(s: &str) -> Result<Self, Self::Err> {
32 let result = match s {
33 host_exports::INIT => Self::Init,
34 host_exports::SEND => Self::Send,
35 host_exports::LOG => Self::Log,
36 host_exports::OP_LIST => Self::OpList,
37 _ => return Err(()),
38 };
39 Ok(result)
40 }
41}
42
43impl AsRef<str> for HostExports {
44 fn as_ref(&self) -> &str {
45 match self {
46 Self::Init => host_exports::INIT,
47 Self::Send => host_exports::SEND,
48 Self::Log => host_exports::LOG,
49 Self::OpList => host_exports::OP_LIST,
50 }
51 }
52}
53
54impl std::fmt::Display for HostExports {
55 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
56 f.write_str(self.as_ref())
57 }
58}
59
60pub mod guest_exports {
62 pub const INIT: &str = "__wasmrs_init";
64
65 pub const SEND: &str = "__wasmrs_send";
67
68 pub const OP_LIST_REQUEST: &str = "__wasmrs_op_list_request";
70
71 pub const VERSION_1: &str = "__wasmrs_v1";
73
74 pub const TINYGO_START: &str = "_start";
76
77 pub const REQUIRED_STARTS: [&str; 2] = [TINYGO_START, INIT];
79}
80
81#[derive(Debug, Copy, Clone, EnumIter)]
83#[allow(missing_docs)]
84pub enum GuestExports {
85 Init,
86 Start,
87 OpListRequest,
88 Send,
89 Version1,
90}
91
92impl FromStr for GuestExports {
93 type Err = ();
94
95 fn from_str(s: &str) -> Result<Self, Self::Err> {
96 let result = match s {
97 guest_exports::INIT => Self::Init,
98 guest_exports::TINYGO_START => Self::Start,
99 guest_exports::OP_LIST_REQUEST => Self::OpListRequest,
100 guest_exports::SEND => Self::Send,
101 guest_exports::VERSION_1 => Self::Version1,
102 _ => return Err(()),
103 };
104 Ok(result)
105 }
106}
107
108impl AsRef<str> for GuestExports {
109 fn as_ref(&self) -> &str {
110 match self {
111 GuestExports::Init => guest_exports::INIT,
112 GuestExports::Start => guest_exports::TINYGO_START,
113 GuestExports::Send => guest_exports::SEND,
114 GuestExports::OpListRequest => guest_exports::OP_LIST_REQUEST,
115 GuestExports::Version1 => guest_exports::VERSION_1,
116 }
117 }
118}
119
120impl std::fmt::Display for GuestExports {
121 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
122 f.write_str(self.as_ref())
123 }
124}