use core::ops::{Deref, DerefMut};
use crate::describe::*;
pub trait IntoWasmAbi: WasmDescribe {
type Abi: WasmAbi;
fn into_abi(self) -> Self::Abi;
}
pub trait FromWasmAbi: WasmDescribe {
type Abi: WasmAbi;
unsafe fn from_abi(js: Self::Abi) -> Self;
}
pub trait RefFromWasmAbi: WasmDescribe {
type Abi: WasmAbi;
type Anchor: Deref<Target = Self>;
unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor;
}
pub trait RefMutFromWasmAbi: WasmDescribe {
type Abi: WasmAbi;
type Anchor: DerefMut<Target = Self>;
unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor;
}
pub trait OptionIntoWasmAbi: IntoWasmAbi {
fn none() -> Self::Abi;
}
pub trait OptionFromWasmAbi: FromWasmAbi {
fn is_none(abi: &Self::Abi) -> bool;
}
pub unsafe trait WasmAbi {}
unsafe impl WasmAbi for u32 {}
unsafe impl WasmAbi for i32 {}
unsafe impl WasmAbi for f32 {}
unsafe impl WasmAbi for f64 {}
pub trait ReturnWasmAbi: WasmDescribe {
type Abi: WasmAbi;
fn return_abi(self) -> Self::Abi;
}
impl<T: IntoWasmAbi> ReturnWasmAbi for T {
type Abi = T::Abi;
#[inline]
fn return_abi(self) -> Self::Abi {
self.into_abi()
}
}