use crate::{
__wry_submit_js_function, JsValue,
encode::{BatchableResult, BinaryEncode, EncodeTypeDef},
};
#[doc(hidden)]
pub use crate::batch::Runtime;
#[doc(hidden)]
pub use crate::encode::TypeTag;
#[doc(hidden)]
pub use crate::function_registry::{
InlineJsModule, JsClassMemberKind, JsClassMemberSpec, JsExportSpec, JsFunctionSpec,
LazyJsFunction,
};
#[doc(hidden)]
pub use crate::js_helpers::js_extract_rust_handle as extract_rust_handle;
#[doc(hidden)]
pub use inventory;
#[doc(hidden)]
pub mod object_store {
pub use crate::object_store::{
ObjectHandle, create_js_wrapper, drop_object, insert_object, remove_object, with_object,
with_object_mut,
};
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct WasmWord(pub u32);
pub struct Ref<'b, T: ?Sized + 'b> {
pub(crate) inner: core::cell::Ref<'b, T>,
}
impl<T: ?Sized> core::ops::Deref for Ref<'_, T> {
type Target = T;
fn deref(&self) -> &Self::Target {
&self.inner
}
}
impl<T: ?Sized> core::borrow::Borrow<T> for Ref<'_, T> {
fn borrow(&self) -> &T {
self
}
}
pub struct RefMut<'b, T: ?Sized + 'b> {
pub(crate) inner: core::cell::RefMut<'b, T>,
}
impl<T: ?Sized> core::ops::Deref for RefMut<'_, T> {
type Target = T;
fn deref(&self) -> &Self::Target {
&self.inner
}
}
impl<T: ?Sized> core::ops::DerefMut for RefMut<'_, T> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner
}
}
impl<T: ?Sized> core::borrow::Borrow<T> for RefMut<'_, T> {
fn borrow(&self) -> &T {
self
}
}
impl<T: ?Sized> core::borrow::BorrowMut<T> for RefMut<'_, T> {
fn borrow_mut(&mut self) -> &mut T {
self
}
}
pub mod marker {
pub unsafe trait ErasableGeneric {
type Repr: 'static;
}
unsafe impl<T: ErasableGeneric> ErasableGeneric for &T {
type Repr = &'static T::Repr;
}
unsafe impl<T: ErasableGeneric> ErasableGeneric for &mut T {
type Repr = &'static mut T::Repr;
}
pub trait ErasableGenericOwn<ConcreteTarget>: ErasableGeneric {}
impl<T, ConcreteTarget> ErasableGenericOwn<ConcreteTarget> for T
where
ConcreteTarget: ErasableGeneric,
T: ErasableGeneric<Repr = <ConcreteTarget as ErasableGeneric>::Repr>,
{
}
pub trait ErasableGenericBorrow<Target: ?Sized> {}
impl<'a, T: ?Sized + 'a, ConcreteTarget: ?Sized + 'static> ErasableGenericBorrow<ConcreteTarget>
for T
where
&'static ConcreteTarget: ErasableGeneric,
&'a T: ErasableGeneric<Repr = <&'static ConcreteTarget as ErasableGeneric>::Repr>,
{
}
pub trait ErasableGenericBorrowMut<Target: ?Sized> {}
impl<'a, T: ?Sized + 'a, ConcreteTarget: ?Sized + 'static>
ErasableGenericBorrowMut<ConcreteTarget> for T
where
&'static mut ConcreteTarget: ErasableGeneric,
&'a mut T: ErasableGeneric<Repr = <&'static mut ConcreteTarget as ErasableGeneric>::Repr>,
{
}
}
#[inline]
pub fn wbg_cast<From, To>(value: From) -> To
where
From: BinaryEncode + EncodeTypeDef,
To: BatchableResult + EncodeTypeDef,
{
let func: LazyJsFunction<fn(From) -> To> = __wry_submit_js_function!("(a0) => a0");
func.call(value)
}
#[cfg(feature = "std")]
pub fn panic_to_panic_error(val: std::boxed::Box<dyn std::any::Any + Send>) -> JsValue {
let maybe_panic_msg: Option<&str> = if let Some(s) = val.downcast_ref::<&str>() {
Some(s)
} else if let Some(s) = val.downcast_ref::<std::string::String>() {
Some(s)
} else {
None
};
JsValue::from_str(maybe_panic_msg.unwrap_or("Rust panic"))
}