diff options
Diffstat (limited to 'crates/types')
| -rw-r--r-- | crates/types/src/value.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/crates/types/src/value.rs b/crates/types/src/value.rs index 782cdb8..129b7c1 100644 --- a/crates/types/src/value.rs +++ b/crates/types/src/value.rs @@ -232,3 +232,43 @@ impl_conversion_for_wasmvalue! { ExternRef => RefExtern, as_ref_extern, "Return the [`ExternRef`] from a `WasmValue`, if it is one"; FuncRef => RefFunc, as_ref_func, "Return the [`FuncRef`] from a `WasmValue`, if it is one"; } + +impl From<u32> for WasmValue { + #[inline] + fn from(i: u32) -> Self { + Self::I32(i as i32) + } +} + +impl TryFrom<WasmValue> for u32 { + type Error = (); + + #[inline] + fn try_from(value: WasmValue) -> Result<Self, Self::Error> { + if let WasmValue::I32(i) = value { + Ok(i as u32) + } else { + Err(()) + } + } +} + +impl From<u64> for WasmValue { + #[inline] + fn from(i: u64) -> Self { + Self::I64(i as i64) + } +} + +impl TryFrom<WasmValue> for u64 { + type Error = (); + + #[inline] + fn try_from(value: WasmValue) -> Result<Self, Self::Error> { + if let WasmValue::I64(i) = value { + Ok(i as u64) + } else { + Err(()) + } + } +} |
