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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
use super::*;
impl From<u8> for WasiValue {
fn from(value: u8) -> Self {
Self::Unsigned8(value)
}
}
impl From<u16> for WasiValue {
fn from(value: u16) -> Self {
Self::Unsigned16(value)
}
}
impl From<u32> for WasiValue {
fn from(value: u32) -> Self {
Self::Unsigned32(value)
}
}
impl From<u64> for WasiValue {
fn from(value: u64) -> Self {
Self::Unsigned64(value)
}
}
impl From<i8> for WasiValue {
fn from(value: i8) -> Self {
Self::Integer8(value)
}
}
impl From<i16> for WasiValue {
fn from(value: i16) -> Self {
Self::Integer16(value)
}
}
impl From<i32> for WasiValue {
fn from(value: i32) -> Self {
Self::Integer32(value)
}
}
impl From<i64> for WasiValue {
fn from(value: i64) -> Self {
Self::Integer64(value)
}
}
impl From<f32> for WasiValue {
fn from(value: f32) -> Self {
Self::Float32(value)
}
}
impl From<f64> for WasiValue {
fn from(value: f64) -> Self {
Self::Float64(value)
}
}
impl WasiValue {
/// Check if the value is a boolean
pub fn is_bool(&self) -> bool {
self.as_bool().is_some()
}
/// Check if the value is an 8-bit unsigned integer
pub fn is_u8(&self) -> bool {
self.as_u8().is_some()
}
/// Check if the value is a 16-bit unsigned integer
pub fn is_u16(&self) -> bool {
self.as_u16().is_some()
}
/// Check if the value is a 32-bit unsigned integer
pub fn is_u32(&self) -> bool {
self.as_u32().is_some()
}
/// Check if the value is a 64-bit unsigned integer
pub fn is_u64(&self) -> bool {
self.as_u64().is_some()
}
/// Check if the value is an 8-bit signed integer
pub fn is_i8(&self) -> bool {
self.as_i8().is_some()
}
/// Check if the value is a 16-bit signed integer
pub fn is_i16(&self) -> bool {
self.as_i16().is_some()
}
/// Check if the value is a 32-bit signed integer
pub fn is_i32(&self) -> bool {
self.as_i32().is_some()
}
/// Check if the value is a 64-bit signed integer
pub fn is_i64(&self) -> bool {
self.as_i64().is_some()
}
/// Check if the value is a 32-bit floating point number
pub fn is_f32(&self) -> bool {
self.as_f32().is_some()
}
/// Check if the value is a 64-bit floating point number
pub fn is_f64(&self) -> bool {
self.as_f64().is_some()
}
/// Check if the value is a unicode character
pub fn is_unicode(&self) -> bool {
self.as_unicode().is_some()
}
/// Check if the value is a UTF-8 string
pub fn is_utf8(&self) -> bool {
self.as_utf8().is_some()
}
/// Check if the value is a record
pub fn is_structure(&self) -> bool {
self.as_structure().is_some()
}
}
impl WasiValue {
/// Try to convert the value to a boolean
pub fn as_bool(&self) -> Option<bool> {
match self {
Self::Boolean(v) => Some(*v),
_ => None,
}
}
/// Try to convert the value to an 8-bit unsigned integer
pub fn as_u8(&self) -> Option<u8> {
match self {
Self::Unsigned8(v) => Some(*v),
_ => None,
}
}
/// Try to convert the value to a 16-bit unsigned integer
pub fn as_u16(&self) -> Option<u16> {
match self {
Self::Unsigned16(v) => Some(*v),
_ => None,
}
}
/// Try to convert the value to a 32-bit unsigned integer
pub fn as_u32(&self) -> Option<u32> {
match self {
Self::Unsigned32(v) => Some(*v),
_ => None,
}
}
/// Try to convert the value to a 64-bit unsigned integer
pub fn as_u64(&self) -> Option<u64> {
match self {
Self::Unsigned64(v) => Some(*v),
_ => None,
}
}
/// Try to convert the value to an 8-bit signed integer
pub fn as_i8(&self) -> Option<i8> {
match self {
Self::Integer8(v) => Some(*v),
_ => None,
}
}
/// Try to convert the value to a 16-bit signed integer
pub fn as_i16(&self) -> Option<i16> {
match self {
Self::Integer16(v) => Some(*v),
_ => None,
}
}
/// Try to convert the value to a 32-bit signed integer
pub fn as_i32(&self) -> Option<i32> {
match self {
Self::Integer32(v) => Some(*v),
_ => None,
}
}
/// Try to convert the value to a 64-bit signed integer
pub fn as_i64(&self) -> Option<i64> {
match self {
Self::Integer64(v) => Some(*v),
_ => None,
}
}
/// Try to convert the value to a 32-bit floating point number
pub fn as_f32(&self) -> Option<f32> {
match self {
Self::Float32(v) => Some(*v),
_ => None,
}
}
/// Try to convert the value to a 64-bit floating point number
pub fn as_f64(&self) -> Option<f64> {
match self {
Self::Float64(v) => Some(*v),
_ => None,
}
}
/// Try to convert the value to a unicode character
pub fn as_unicode(&self) -> Option<char> {
match self {
Self::Unicode(v) => Some(*v),
_ => None,
}
}
/// Try to convert the value to a UTF-8 string
pub fn as_utf8(&self) -> Option<&str> {
match self {
Self::UTF8(v) => Some(v),
_ => None,
}
}
/// Try to convert the value to a record
pub fn as_structure(&self) -> Option<&WasiObject> {
match self {
Self::Object(v) => Some(v),
_ => None,
}
}
}