use crate::__rt::JsRef;
use crate::{JsCast, JsValue};
use core::marker::PhantomData;
use super::{
FromWasmAbi, IntoWasmAbi, JsGeneric, OptionFromWasmAbi, OptionIntoWasmAbi, RefFromWasmAbi,
UpcastFrom, WasmAbi,
};
impl<T: JsGeneric> IntoWasmAbi for T {}
impl<T: JsGeneric> FromWasmAbi for T {}
macro_rules! value_wasm_abi {
($($ty:ty),* $(,)?) => {$(
impl IntoWasmAbi for $ty {}
impl FromWasmAbi for $ty {}
)*};
}
value_wasm_abi!(
(),
bool,
char,
f32,
f64,
usize,
isize,
alloc::string::String,
i8,
i16,
i32,
i64,
i128,
u8,
u16,
u32,
u64,
u128,
);
macro_rules! value_upcast {
($($ty:ty),* $(,)?) => {$(
impl UpcastFrom<$ty> for $ty {}
impl UpcastFrom<$ty> for JsValue {}
)*};
}
value_upcast!(
bool, char, f32, f64, usize, isize, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128,
);
impl<T: crate::__rt::BinaryEncode + crate::__rt::EncodeTypeDef> IntoWasmAbi
for core::option::Option<T>
{
}
impl<T: crate::__rt::BinaryDecode + crate::__rt::EncodeTypeDef> FromWasmAbi
for core::option::Option<T>
{
}
impl IntoWasmAbi for &JsValue {}
impl<T> OptionIntoWasmAbi for T where T: IntoWasmAbi {}
impl<T> OptionFromWasmAbi for T where T: FromWasmAbi {}
impl<T: ?Sized> WasmAbi for T {}
impl<T: ?Sized> RefFromWasmAbi for T {}
impl UpcastFrom<JsValue> for JsValue {}
pub struct JsCastAnchor<T: JsCast> {
value: JsValue,
_marker: PhantomData<T>,
}
impl<T: JsCast> core::ops::Deref for JsCastAnchor<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
T::unchecked_from_js_ref(&self.value)
}
}
impl<T: JsCast> JsCastAnchor<T> {
#[doc(hidden)]
pub fn next_borrowed() -> Self {
JsCastAnchor {
value: JsValue::from_ref(JsRef::next_borrowed_ref()),
_marker: PhantomData,
}
}
}