mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 04:08:19 +00:00
implement wasm traits for roc_std::RocBox
This commit is contained in:
parent
b022175489
commit
625b9c161a
4 changed files with 27 additions and 4 deletions
|
@ -1,7 +1,7 @@
|
|||
use roc_error_macros::internal_error;
|
||||
use roc_gen_wasm::wasm32_sized::Wasm32Sized;
|
||||
use roc_mono::layout::Builtin;
|
||||
use roc_std::{RocDec, RocList, RocOrder, RocResult, RocStr, I128, U128};
|
||||
use roc_std::{RocBox, RocDec, RocList, RocOrder, RocResult, RocStr, I128, U128};
|
||||
use roc_wasm_module::round_up_to_alignment;
|
||||
use std::convert::TryInto;
|
||||
|
||||
|
@ -104,6 +104,17 @@ impl<T: FromWasm32Memory + Clone> FromWasm32Memory for RocList<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: FromWasm32Memory + Clone> FromWasm32Memory for RocBox<T> {
|
||||
fn decode(memory: &[u8], offset: u32) -> Self {
|
||||
let ptr = <u32 as FromWasm32Memory>::decode(memory, offset + 4 * Builtin::WRAPPER_PTR);
|
||||
debug_assert_ne!(ptr, 0);
|
||||
|
||||
let value = <T as FromWasm32Memory>::decode(memory, ptr);
|
||||
|
||||
RocBox::new(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, E> FromWasm32Memory for RocResult<T, E>
|
||||
where
|
||||
T: FromWasm32Memory + Wasm32Sized,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue