diff options
| author | Mica White <botahamec@outlook.com> | 2026-07-29 21:25:01 -0400 |
|---|---|---|
| committer | Mica White <botahamec@outlook.com> | 2026-07-29 21:25:01 -0400 |
| commit | 5ab4339c98179958b11b716b5887ecd3224666e2 (patch) | |
| tree | f9c7f01d142cbdf72471b40a5d36fe92bbfbeb6f /crates/types | |
| parent | c7c26e8900e86f8b2116648e988b1e34c85f4077 (diff) | |
Support tortuisebota-tortuise
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(()) + } + } +} |
