use frunk::{hlist, hlist_pat, HList};
use wasmer::{FromToNativeWasmType, WasmTypeList};
use crate::{memory_layout::FlatLayout, primitive_types::FlatType};
pub trait WasmerResults: FlatLayout {
type Results: WasmTypeList;
fn from_wasmer(results: Self::Results) -> Self;
fn into_wasmer(self) -> Self::Results;
}
impl WasmerResults for HList![] {
type Results = ();
fn from_wasmer((): Self::Results) -> Self::Flat {
hlist![]
}
fn into_wasmer(self) -> Self::Results {}
}
impl<T> WasmerResults for HList![T]
where
T: FlatType + FromToNativeWasmType,
{
type Results = T;
fn from_wasmer(value: Self::Results) -> Self {
hlist![value]
}
fn into_wasmer(self) -> Self::Results {
let hlist_pat![value] = self;
value
}
}