runtime: Better `i32` to/from `u32` conversion
use super::{class::EnumPayload, AscHeap, AscType, AscValue};
+use std::convert::TryFrom;
use std::fmt;
use std::marker::PhantomData;
use std::mem::size_of;
@@ -29,7 +30,7 @@ impl<T> fmt::Debug for AscPtr<T> {
impl<C> AscPtr<C> {
/// A raw pointer to be passed to wasm. Wasmtime uses `i32` for 32 bits wasm integers.
pub(crate) fn wasm_ptr(self) -> i32 {
- i32::from_le_bytes(self.0.to_le_bytes())
+ self.0 as i32
}
}
@@ -77,7 +78,7 @@ impl<C: AscType> AscPtr<C> {
/// WASM integers do not carry sign information, but wasmtime uses `i32` for them.
impl<C> From<i32> for AscPtr<C> {
fn from(ptr: i32) -> Self {
- AscPtr(u32::from_le_bytes(ptr.to_le_bytes()), PhantomData)
+ AscPtr(u32::try_from(ptr).unwrap(), PhantomData)
}
}
