diff --git a/tests/expand/generic_constrained_struct.expanded.rs b/tests/expand/generic_constrained_struct.expanded.rs new file mode 100644 index 0000000..d36d195 --- /dev/null +++ b/tests/expand/generic_constrained_struct.expanded.rs @@ -0,0 +1,2162 @@ +use tsify::Tsify; +pub trait Constraint {} +#[tsify(into_wasm_abi, from_wasm_abi)] +pub struct GenericStruct { + x: T, +} +const _: () = { + extern crate serde as _serde; + use tsify::Tsify; + use wasm_bindgen::{ + convert::{ + FromWasmAbi, VectorFromWasmAbi, IntoWasmAbi, VectorIntoWasmAbi, + OptionFromWasmAbi, OptionIntoWasmAbi, RefFromWasmAbi, + }, + describe::WasmDescribe, describe::WasmDescribeVector, prelude::*, + }; + #[repr(transparent)] + pub struct JsType { + obj: wasm_bindgen::JsValue, + } + #[automatically_derived] + impl ::core::clone::Clone for JsType { + #[inline] + fn clone(&self) -> JsType { + JsType { + obj: ::core::clone::Clone::clone(&self.obj), + } + } + } + #[automatically_derived] + const _: () = { + use wasm_bindgen::convert::TryFromJsValue; + use wasm_bindgen::convert::{IntoWasmAbi, FromWasmAbi}; + use wasm_bindgen::convert::{OptionIntoWasmAbi, OptionFromWasmAbi}; + use wasm_bindgen::convert::{RefFromWasmAbi, LongRefFromWasmAbi}; + use wasm_bindgen::describe::WasmDescribe; + use wasm_bindgen::{JsValue, JsCast}; + use wasm_bindgen::__rt::{core, marker::ErasableGeneric}; + #[automatically_derived] + impl WasmDescribe for JsType { + fn describe() { + use wasm_bindgen::describe::*; + inform(NAMED_EXTERNREF); + inform(13u32); + inform(71u32); + inform(101u32); + inform(110u32); + inform(101u32); + inform(114u32); + inform(105u32); + inform(99u32); + inform(83u32); + inform(116u32); + inform(114u32); + inform(117u32); + inform(99u32); + inform(116u32); + } + } + #[automatically_derived] + impl IntoWasmAbi for JsType { + type Abi = ::Abi; + #[inline] + fn into_abi(self) -> Self::Abi { + self.obj.into_abi() + } + } + #[automatically_derived] + impl OptionIntoWasmAbi for JsType { + #[inline] + fn none() -> Self::Abi { + 0 + } + } + #[automatically_derived] + impl<'a> OptionIntoWasmAbi for &'a JsType { + #[inline] + fn none() -> Self::Abi { + 0 + } + } + #[automatically_derived] + impl FromWasmAbi for JsType { + type Abi = ::Abi; + #[inline] + unsafe fn from_abi(js: Self::Abi) -> Self { + JsType { + obj: JsValue::from_abi(js).into(), + } + } + } + #[automatically_derived] + impl OptionFromWasmAbi for JsType { + #[inline] + fn is_none(abi: &Self::Abi) -> bool { + *abi == 0 + } + } + #[automatically_derived] + impl<'a> IntoWasmAbi for &'a JsType { + type Abi = <&'a JsValue as IntoWasmAbi>::Abi; + #[inline] + fn into_abi(self) -> Self::Abi { + (&self.obj).into_abi() + } + } + #[automatically_derived] + impl RefFromWasmAbi for JsType { + type Abi = ::Abi; + type Anchor = wasm_bindgen::__rt::core::mem::ManuallyDrop; + #[inline] + unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor { + let tmp = ::ref_from_abi(js); + wasm_bindgen::__rt::core::mem::ManuallyDrop::new(JsType { + obj: wasm_bindgen::__rt::core::mem::ManuallyDrop::into_inner(tmp) + .into(), + }) + } + } + #[automatically_derived] + impl LongRefFromWasmAbi for JsType { + type Abi = ::Abi; + type Anchor = JsType; + #[inline] + unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor { + let tmp = ::long_ref_from_abi(js); + JsType { obj: tmp.into() } + } + } + #[automatically_derived] + impl AsRef for JsType { + #[inline] + fn as_ref(&self) -> &JsValue { + self.obj.as_ref() + } + } + #[automatically_derived] + impl AsRef for JsType { + #[inline] + fn as_ref(&self) -> &JsType { + self + } + } + #[automatically_derived] + impl wasm_bindgen::IntoJsGeneric for JsType + where + JsType: wasm_bindgen::JsGeneric, + { + type JsCanon = JsType; + #[inline] + fn to_js(self) -> JsType { + unsafe { + wasm_bindgen::__rt::core::mem::transmute_copy( + &wasm_bindgen::__rt::core::mem::ManuallyDrop::new(self), + ) + } + } + } + #[automatically_derived] + impl From for JsType { + #[inline] + fn from(obj: JsValue) -> Self { + JsType { obj: obj.into() } + } + } + #[automatically_derived] + impl From for JsValue { + #[inline] + fn from(obj: JsType) -> JsValue { + obj.obj.into() + } + } + #[automatically_derived] + impl JsCast for JsType { + fn instanceof(val: &JsValue) -> bool { + unsafe fn __wbg_instanceof_JsType_07a4c56f90e9a47b(_: u32) -> u32 { + { + ::core::panicking::panic_fmt( + format_args!("cannot check instanceof on non-wasm targets"), + ); + }; + } + unsafe { + let idx = val.into_abi(); + __wbg_instanceof_JsType_07a4c56f90e9a47b(idx) != 0 + } + } + #[inline] + fn unchecked_from_js(val: JsValue) -> Self { + JsType { obj: val.into() } + } + #[inline] + fn unchecked_from_js_ref(val: &JsValue) -> &Self { + unsafe { &*(val as *const JsValue as *const Self) } + } + } + unsafe impl ErasableGeneric for JsType { + type Repr = JsValue; + } + }; + #[automatically_derived] + impl wasm_bindgen::sys::Promising for JsType { + type Resolution = JsType; + } + #[automatically_derived] + impl wasm_bindgen::__rt::core::ops::Deref for JsType { + type Target = wasm_bindgen::JsValue; + #[inline] + fn deref(&self) -> &wasm_bindgen::JsValue { + &self.obj + } + } + #[automatically_derived] + impl wasm_bindgen::convert::UpcastFrom for wasm_bindgen::JsValue {} + #[automatically_derived] + impl wasm_bindgen::convert::UpcastFrom + for wasm_bindgen::sys::JsOption {} + #[automatically_derived] + impl wasm_bindgen::convert::UpcastFrom + for wasm_bindgen::sys::JsNullable {} + #[automatically_derived] + impl wasm_bindgen::convert::UpcastFrom for JsType {} + #[automatically_derived] + impl wasm_bindgen::convert::UpcastFrom + for wasm_bindgen::sys::JsOption {} + #[automatically_derived] + impl wasm_bindgen::convert::UpcastFrom + for wasm_bindgen::sys::JsNullable {} + #[automatically_derived] + impl Tsify for GenericStruct { + type JsType = JsType; + const DECL: &'static str = "export interface GenericStruct {\n x: T;\n}"; + const SERIALIZATION_CONFIG: tsify::SerializationConfig = tsify::SerializationConfig { + missing_as_null: false, + hashmap_as_object: false, + large_number_types_as_bigints: false, + }; + } + #[automatically_derived] + impl WasmDescribe for GenericStruct { + #[inline] + fn describe() { + ::JsType::describe() + } + } + #[automatically_derived] + impl WasmDescribeVector for GenericStruct { + #[inline] + fn describe_vector() { + ::JsType::describe_vector() + } + } + #[automatically_derived] + impl IntoWasmAbi for &GenericStruct + where + GenericStruct: _serde::Serialize, + { + type Abi = ::Abi; + #[inline] + fn into_abi(self) -> Self::Abi { + match self.into_js() { + Ok(js) => js.into_abi(), + Err(err) => { + let loc = core::panic::Location::caller(); + let msg = ::alloc::__export::must_use({ + ::alloc::fmt::format( + format_args!( + "(Converting type failed) {0} ({1}:{2}:{3})", err, loc + .file(), loc.line(), loc.column(), + ), + ) + }); + { + ::core::panicking::panic_display(&msg); + }; + } + } + } + } + #[automatically_derived] + impl IntoWasmAbi for GenericStruct + where + GenericStruct: _serde::Serialize, + { + type Abi = ::Abi; + #[inline] + fn into_abi(self) -> Self::Abi { + (&self).into_abi() + } + } + #[automatically_derived] + impl OptionIntoWasmAbi for GenericStruct + where + GenericStruct: _serde::Serialize, + { + #[inline] + fn none() -> Self::Abi { + ::none() + } + } + #[automatically_derived] + impl From> for JsValue + where + GenericStruct: _serde::Serialize, + { + #[inline] + fn from(value: GenericStruct) -> Self { + match value.into_js() { + Ok(js) => js.into(), + Err(err) => { + let loc = core::panic::Location::caller(); + let msg = ::alloc::__export::must_use({ + ::alloc::fmt::format( + format_args!( + "(Converting type failed) {0} ({1}:{2}:{3})", err, loc + .file(), loc.line(), loc.column(), + ), + ) + }); + { + ::core::panicking::panic_display(&msg); + }; + } + } + } + } + #[automatically_derived] + impl VectorIntoWasmAbi for GenericStruct + where + GenericStruct: _serde::Serialize, + { + type Abi = ::Abi; + #[inline] + fn vector_into_abi(vector: Box<[Self]>) -> Self::Abi { + let values = vector + .iter() + .map(|value| match value.into_js() { + Ok(js) => js.into(), + Err(err) => { + let loc = core::panic::Location::caller(); + let msg = ::alloc::__export::must_use({ + ::alloc::fmt::format( + format_args!( + "(Converting type failed) {0} ({1}:{2}:{3})", err, loc + .file(), loc.line(), loc.column(), + ), + ) + }); + { + ::core::panicking::panic_display(&msg); + }; + } + }) + .collect(); + JsValue::vector_into_abi(values) + } + } + #[automatically_derived] + impl FromWasmAbi for GenericStruct + where + Self: _serde::de::DeserializeOwned, + { + type Abi = ::Abi; + #[inline] + unsafe fn from_abi(js: Self::Abi) -> Self { + let result = Self::from_js(&JsType::from_abi(js)); + if let Err(err) = result { + wasm_bindgen::throw_str(err.to_string().as_ref()); + } + result.unwrap_throw() + } + } + #[automatically_derived] + impl OptionFromWasmAbi for GenericStruct + where + Self: _serde::de::DeserializeOwned, + { + #[inline] + fn is_none(js: &Self::Abi) -> bool { + ::is_none(js) + } + } + pub struct SelfOwner(T); + #[automatically_derived] + impl ::core::ops::Deref for SelfOwner { + type Target = T; + fn deref(&self) -> &Self::Target { + &self.0 + } + } + #[automatically_derived] + impl RefFromWasmAbi for GenericStruct + where + Self: _serde::de::DeserializeOwned, + { + type Abi = ::Abi; + type Anchor = SelfOwner; + unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor { + let result = Self::from_js(&*JsType::ref_from_abi(js)); + if let Err(err) = result { + wasm_bindgen::throw_str(err.to_string().as_ref()); + } + SelfOwner(result.unwrap_throw()) + } + } + #[automatically_derived] + impl VectorFromWasmAbi for GenericStruct + where + Self: _serde::de::DeserializeOwned, + { + type Abi = ::Abi; + #[inline] + unsafe fn vector_from_abi(js: Self::Abi) -> Box<[Self]> { + JsValue::vector_from_abi(js) + .into_iter() + .map(|value| { + let result = Self::from_js(value); + if let Err(err) = result { + wasm_bindgen::throw_str(err.to_string().as_ref()); + } + result.unwrap_throw() + }) + .collect() + } + } + #[allow(non_upper_case_globals)] + const _: () = { + #[deprecated( + note = "into_wasm_abi/from_wasm_abi are deprecated as they cause memory leaks (https://github.com/madonoharu/tsify/issues/65). Consider using `tsify::Ts` instead." + )] + const _x: () = (); + _x + }; +}; +#[tsify(into_wasm_abi, from_wasm_abi)] +pub struct GenericNewtype(T); +const _: () = { + extern crate serde as _serde; + use tsify::Tsify; + use wasm_bindgen::{ + convert::{ + FromWasmAbi, VectorFromWasmAbi, IntoWasmAbi, VectorIntoWasmAbi, + OptionFromWasmAbi, OptionIntoWasmAbi, RefFromWasmAbi, + }, + describe::WasmDescribe, describe::WasmDescribeVector, prelude::*, + }; + #[repr(transparent)] + pub struct JsType { + obj: wasm_bindgen::JsValue, + } + #[automatically_derived] + impl ::core::clone::Clone for JsType { + #[inline] + fn clone(&self) -> JsType { + JsType { + obj: ::core::clone::Clone::clone(&self.obj), + } + } + } + #[automatically_derived] + const _: () = { + use wasm_bindgen::convert::TryFromJsValue; + use wasm_bindgen::convert::{IntoWasmAbi, FromWasmAbi}; + use wasm_bindgen::convert::{OptionIntoWasmAbi, OptionFromWasmAbi}; + use wasm_bindgen::convert::{RefFromWasmAbi, LongRefFromWasmAbi}; + use wasm_bindgen::describe::WasmDescribe; + use wasm_bindgen::{JsValue, JsCast}; + use wasm_bindgen::__rt::{core, marker::ErasableGeneric}; + #[automatically_derived] + impl WasmDescribe for JsType { + fn describe() { + use wasm_bindgen::describe::*; + inform(NAMED_EXTERNREF); + inform(14u32); + inform(71u32); + inform(101u32); + inform(110u32); + inform(101u32); + inform(114u32); + inform(105u32); + inform(99u32); + inform(78u32); + inform(101u32); + inform(119u32); + inform(116u32); + inform(121u32); + inform(112u32); + inform(101u32); + } + } + #[automatically_derived] + impl IntoWasmAbi for JsType { + type Abi = ::Abi; + #[inline] + fn into_abi(self) -> Self::Abi { + self.obj.into_abi() + } + } + #[automatically_derived] + impl OptionIntoWasmAbi for JsType { + #[inline] + fn none() -> Self::Abi { + 0 + } + } + #[automatically_derived] + impl<'a> OptionIntoWasmAbi for &'a JsType { + #[inline] + fn none() -> Self::Abi { + 0 + } + } + #[automatically_derived] + impl FromWasmAbi for JsType { + type Abi = ::Abi; + #[inline] + unsafe fn from_abi(js: Self::Abi) -> Self { + JsType { + obj: JsValue::from_abi(js).into(), + } + } + } + #[automatically_derived] + impl OptionFromWasmAbi for JsType { + #[inline] + fn is_none(abi: &Self::Abi) -> bool { + *abi == 0 + } + } + #[automatically_derived] + impl<'a> IntoWasmAbi for &'a JsType { + type Abi = <&'a JsValue as IntoWasmAbi>::Abi; + #[inline] + fn into_abi(self) -> Self::Abi { + (&self.obj).into_abi() + } + } + #[automatically_derived] + impl RefFromWasmAbi for JsType { + type Abi = ::Abi; + type Anchor = wasm_bindgen::__rt::core::mem::ManuallyDrop; + #[inline] + unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor { + let tmp = ::ref_from_abi(js); + wasm_bindgen::__rt::core::mem::ManuallyDrop::new(JsType { + obj: wasm_bindgen::__rt::core::mem::ManuallyDrop::into_inner(tmp) + .into(), + }) + } + } + #[automatically_derived] + impl LongRefFromWasmAbi for JsType { + type Abi = ::Abi; + type Anchor = JsType; + #[inline] + unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor { + let tmp = ::long_ref_from_abi(js); + JsType { obj: tmp.into() } + } + } + #[automatically_derived] + impl AsRef for JsType { + #[inline] + fn as_ref(&self) -> &JsValue { + self.obj.as_ref() + } + } + #[automatically_derived] + impl AsRef for JsType { + #[inline] + fn as_ref(&self) -> &JsType { + self + } + } + #[automatically_derived] + impl wasm_bindgen::IntoJsGeneric for JsType + where + JsType: wasm_bindgen::JsGeneric, + { + type JsCanon = JsType; + #[inline] + fn to_js(self) -> JsType { + unsafe { + wasm_bindgen::__rt::core::mem::transmute_copy( + &wasm_bindgen::__rt::core::mem::ManuallyDrop::new(self), + ) + } + } + } + #[automatically_derived] + impl From for JsType { + #[inline] + fn from(obj: JsValue) -> Self { + JsType { obj: obj.into() } + } + } + #[automatically_derived] + impl From for JsValue { + #[inline] + fn from(obj: JsType) -> JsValue { + obj.obj.into() + } + } + #[automatically_derived] + impl JsCast for JsType { + fn instanceof(val: &JsValue) -> bool { + unsafe fn __wbg_instanceof_JsType_07a4c56f90e9a47b(_: u32) -> u32 { + { + ::core::panicking::panic_fmt( + format_args!("cannot check instanceof on non-wasm targets"), + ); + }; + } + unsafe { + let idx = val.into_abi(); + __wbg_instanceof_JsType_07a4c56f90e9a47b(idx) != 0 + } + } + #[inline] + fn unchecked_from_js(val: JsValue) -> Self { + JsType { obj: val.into() } + } + #[inline] + fn unchecked_from_js_ref(val: &JsValue) -> &Self { + unsafe { &*(val as *const JsValue as *const Self) } + } + } + unsafe impl ErasableGeneric for JsType { + type Repr = JsValue; + } + }; + #[automatically_derived] + impl wasm_bindgen::sys::Promising for JsType { + type Resolution = JsType; + } + #[automatically_derived] + impl wasm_bindgen::__rt::core::ops::Deref for JsType { + type Target = wasm_bindgen::JsValue; + #[inline] + fn deref(&self) -> &wasm_bindgen::JsValue { + &self.obj + } + } + #[automatically_derived] + impl wasm_bindgen::convert::UpcastFrom for wasm_bindgen::JsValue {} + #[automatically_derived] + impl wasm_bindgen::convert::UpcastFrom + for wasm_bindgen::sys::JsOption {} + #[automatically_derived] + impl wasm_bindgen::convert::UpcastFrom + for wasm_bindgen::sys::JsNullable {} + #[automatically_derived] + impl wasm_bindgen::convert::UpcastFrom for JsType {} + #[automatically_derived] + impl wasm_bindgen::convert::UpcastFrom + for wasm_bindgen::sys::JsOption {} + #[automatically_derived] + impl wasm_bindgen::convert::UpcastFrom + for wasm_bindgen::sys::JsNullable {} + #[automatically_derived] + impl Tsify for GenericNewtype { + type JsType = JsType; + const DECL: &'static str = "export type GenericNewtype = T;"; + const SERIALIZATION_CONFIG: tsify::SerializationConfig = tsify::SerializationConfig { + missing_as_null: false, + hashmap_as_object: false, + large_number_types_as_bigints: false, + }; + } + #[automatically_derived] + impl WasmDescribe for GenericNewtype { + #[inline] + fn describe() { + ::JsType::describe() + } + } + #[automatically_derived] + impl WasmDescribeVector for GenericNewtype { + #[inline] + fn describe_vector() { + ::JsType::describe_vector() + } + } + #[automatically_derived] + impl IntoWasmAbi for &GenericNewtype + where + GenericNewtype: _serde::Serialize, + { + type Abi = ::Abi; + #[inline] + fn into_abi(self) -> Self::Abi { + match self.into_js() { + Ok(js) => js.into_abi(), + Err(err) => { + let loc = core::panic::Location::caller(); + let msg = ::alloc::__export::must_use({ + ::alloc::fmt::format( + format_args!( + "(Converting type failed) {0} ({1}:{2}:{3})", err, loc + .file(), loc.line(), loc.column(), + ), + ) + }); + { + ::core::panicking::panic_display(&msg); + }; + } + } + } + } + #[automatically_derived] + impl IntoWasmAbi for GenericNewtype + where + GenericNewtype: _serde::Serialize, + { + type Abi = ::Abi; + #[inline] + fn into_abi(self) -> Self::Abi { + (&self).into_abi() + } + } + #[automatically_derived] + impl OptionIntoWasmAbi for GenericNewtype + where + GenericNewtype: _serde::Serialize, + { + #[inline] + fn none() -> Self::Abi { + ::none() + } + } + #[automatically_derived] + impl From> for JsValue + where + GenericNewtype: _serde::Serialize, + { + #[inline] + fn from(value: GenericNewtype) -> Self { + match value.into_js() { + Ok(js) => js.into(), + Err(err) => { + let loc = core::panic::Location::caller(); + let msg = ::alloc::__export::must_use({ + ::alloc::fmt::format( + format_args!( + "(Converting type failed) {0} ({1}:{2}:{3})", err, loc + .file(), loc.line(), loc.column(), + ), + ) + }); + { + ::core::panicking::panic_display(&msg); + }; + } + } + } + } + #[automatically_derived] + impl VectorIntoWasmAbi for GenericNewtype + where + GenericNewtype: _serde::Serialize, + { + type Abi = ::Abi; + #[inline] + fn vector_into_abi(vector: Box<[Self]>) -> Self::Abi { + let values = vector + .iter() + .map(|value| match value.into_js() { + Ok(js) => js.into(), + Err(err) => { + let loc = core::panic::Location::caller(); + let msg = ::alloc::__export::must_use({ + ::alloc::fmt::format( + format_args!( + "(Converting type failed) {0} ({1}:{2}:{3})", err, loc + .file(), loc.line(), loc.column(), + ), + ) + }); + { + ::core::panicking::panic_display(&msg); + }; + } + }) + .collect(); + JsValue::vector_into_abi(values) + } + } + #[automatically_derived] + impl FromWasmAbi for GenericNewtype + where + Self: _serde::de::DeserializeOwned, + { + type Abi = ::Abi; + #[inline] + unsafe fn from_abi(js: Self::Abi) -> Self { + let result = Self::from_js(&JsType::from_abi(js)); + if let Err(err) = result { + wasm_bindgen::throw_str(err.to_string().as_ref()); + } + result.unwrap_throw() + } + } + #[automatically_derived] + impl OptionFromWasmAbi for GenericNewtype + where + Self: _serde::de::DeserializeOwned, + { + #[inline] + fn is_none(js: &Self::Abi) -> bool { + ::is_none(js) + } + } + pub struct SelfOwner(T); + #[automatically_derived] + impl ::core::ops::Deref for SelfOwner { + type Target = T; + fn deref(&self) -> &Self::Target { + &self.0 + } + } + #[automatically_derived] + impl RefFromWasmAbi for GenericNewtype + where + Self: _serde::de::DeserializeOwned, + { + type Abi = ::Abi; + type Anchor = SelfOwner; + unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor { + let result = Self::from_js(&*JsType::ref_from_abi(js)); + if let Err(err) = result { + wasm_bindgen::throw_str(err.to_string().as_ref()); + } + SelfOwner(result.unwrap_throw()) + } + } + #[automatically_derived] + impl VectorFromWasmAbi for GenericNewtype + where + Self: _serde::de::DeserializeOwned, + { + type Abi = ::Abi; + #[inline] + unsafe fn vector_from_abi(js: Self::Abi) -> Box<[Self]> { + JsValue::vector_from_abi(js) + .into_iter() + .map(|value| { + let result = Self::from_js(value); + if let Err(err) = result { + wasm_bindgen::throw_str(err.to_string().as_ref()); + } + result.unwrap_throw() + }) + .collect() + } + } + #[allow(non_upper_case_globals)] + const _: () = { + #[deprecated( + note = "into_wasm_abi/from_wasm_abi are deprecated as they cause memory leaks (https://github.com/madonoharu/tsify/issues/65). Consider using `tsify::Ts` instead." + )] + const _x: () = (); + _x + }; +}; +#[tsify(into_wasm_abi, from_wasm_abi)] +pub struct GenericAssoc> { + x: T, +} +const _: () = { + extern crate serde as _serde; + use tsify::Tsify; + use wasm_bindgen::{ + convert::{ + FromWasmAbi, VectorFromWasmAbi, IntoWasmAbi, VectorIntoWasmAbi, + OptionFromWasmAbi, OptionIntoWasmAbi, RefFromWasmAbi, + }, + describe::WasmDescribe, describe::WasmDescribeVector, prelude::*, + }; + #[repr(transparent)] + pub struct JsType { + obj: wasm_bindgen::JsValue, + } + #[automatically_derived] + impl ::core::clone::Clone for JsType { + #[inline] + fn clone(&self) -> JsType { + JsType { + obj: ::core::clone::Clone::clone(&self.obj), + } + } + } + #[automatically_derived] + const _: () = { + use wasm_bindgen::convert::TryFromJsValue; + use wasm_bindgen::convert::{IntoWasmAbi, FromWasmAbi}; + use wasm_bindgen::convert::{OptionIntoWasmAbi, OptionFromWasmAbi}; + use wasm_bindgen::convert::{RefFromWasmAbi, LongRefFromWasmAbi}; + use wasm_bindgen::describe::WasmDescribe; + use wasm_bindgen::{JsValue, JsCast}; + use wasm_bindgen::__rt::{core, marker::ErasableGeneric}; + #[automatically_derived] + impl WasmDescribe for JsType { + fn describe() { + use wasm_bindgen::describe::*; + inform(NAMED_EXTERNREF); + inform(12u32); + inform(71u32); + inform(101u32); + inform(110u32); + inform(101u32); + inform(114u32); + inform(105u32); + inform(99u32); + inform(65u32); + inform(115u32); + inform(115u32); + inform(111u32); + inform(99u32); + } + } + #[automatically_derived] + impl IntoWasmAbi for JsType { + type Abi = ::Abi; + #[inline] + fn into_abi(self) -> Self::Abi { + self.obj.into_abi() + } + } + #[automatically_derived] + impl OptionIntoWasmAbi for JsType { + #[inline] + fn none() -> Self::Abi { + 0 + } + } + #[automatically_derived] + impl<'a> OptionIntoWasmAbi for &'a JsType { + #[inline] + fn none() -> Self::Abi { + 0 + } + } + #[automatically_derived] + impl FromWasmAbi for JsType { + type Abi = ::Abi; + #[inline] + unsafe fn from_abi(js: Self::Abi) -> Self { + JsType { + obj: JsValue::from_abi(js).into(), + } + } + } + #[automatically_derived] + impl OptionFromWasmAbi for JsType { + #[inline] + fn is_none(abi: &Self::Abi) -> bool { + *abi == 0 + } + } + #[automatically_derived] + impl<'a> IntoWasmAbi for &'a JsType { + type Abi = <&'a JsValue as IntoWasmAbi>::Abi; + #[inline] + fn into_abi(self) -> Self::Abi { + (&self.obj).into_abi() + } + } + #[automatically_derived] + impl RefFromWasmAbi for JsType { + type Abi = ::Abi; + type Anchor = wasm_bindgen::__rt::core::mem::ManuallyDrop; + #[inline] + unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor { + let tmp = ::ref_from_abi(js); + wasm_bindgen::__rt::core::mem::ManuallyDrop::new(JsType { + obj: wasm_bindgen::__rt::core::mem::ManuallyDrop::into_inner(tmp) + .into(), + }) + } + } + #[automatically_derived] + impl LongRefFromWasmAbi for JsType { + type Abi = ::Abi; + type Anchor = JsType; + #[inline] + unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor { + let tmp = ::long_ref_from_abi(js); + JsType { obj: tmp.into() } + } + } + #[automatically_derived] + impl AsRef for JsType { + #[inline] + fn as_ref(&self) -> &JsValue { + self.obj.as_ref() + } + } + #[automatically_derived] + impl AsRef for JsType { + #[inline] + fn as_ref(&self) -> &JsType { + self + } + } + #[automatically_derived] + impl wasm_bindgen::IntoJsGeneric for JsType + where + JsType: wasm_bindgen::JsGeneric, + { + type JsCanon = JsType; + #[inline] + fn to_js(self) -> JsType { + unsafe { + wasm_bindgen::__rt::core::mem::transmute_copy( + &wasm_bindgen::__rt::core::mem::ManuallyDrop::new(self), + ) + } + } + } + #[automatically_derived] + impl From for JsType { + #[inline] + fn from(obj: JsValue) -> Self { + JsType { obj: obj.into() } + } + } + #[automatically_derived] + impl From for JsValue { + #[inline] + fn from(obj: JsType) -> JsValue { + obj.obj.into() + } + } + #[automatically_derived] + impl JsCast for JsType { + fn instanceof(val: &JsValue) -> bool { + unsafe fn __wbg_instanceof_JsType_07a4c56f90e9a47b(_: u32) -> u32 { + { + ::core::panicking::panic_fmt( + format_args!("cannot check instanceof on non-wasm targets"), + ); + }; + } + unsafe { + let idx = val.into_abi(); + __wbg_instanceof_JsType_07a4c56f90e9a47b(idx) != 0 + } + } + #[inline] + fn unchecked_from_js(val: JsValue) -> Self { + JsType { obj: val.into() } + } + #[inline] + fn unchecked_from_js_ref(val: &JsValue) -> &Self { + unsafe { &*(val as *const JsValue as *const Self) } + } + } + unsafe impl ErasableGeneric for JsType { + type Repr = JsValue; + } + }; + #[automatically_derived] + impl wasm_bindgen::sys::Promising for JsType { + type Resolution = JsType; + } + #[automatically_derived] + impl wasm_bindgen::__rt::core::ops::Deref for JsType { + type Target = wasm_bindgen::JsValue; + #[inline] + fn deref(&self) -> &wasm_bindgen::JsValue { + &self.obj + } + } + #[automatically_derived] + impl wasm_bindgen::convert::UpcastFrom for wasm_bindgen::JsValue {} + #[automatically_derived] + impl wasm_bindgen::convert::UpcastFrom + for wasm_bindgen::sys::JsOption {} + #[automatically_derived] + impl wasm_bindgen::convert::UpcastFrom + for wasm_bindgen::sys::JsNullable {} + #[automatically_derived] + impl wasm_bindgen::convert::UpcastFrom for JsType {} + #[automatically_derived] + impl wasm_bindgen::convert::UpcastFrom + for wasm_bindgen::sys::JsOption {} + #[automatically_derived] + impl wasm_bindgen::convert::UpcastFrom + for wasm_bindgen::sys::JsNullable {} + #[automatically_derived] + impl> Tsify for GenericAssoc { + type JsType = JsType; + const DECL: &'static str = "export interface GenericAssoc {\n x: T;\n}"; + const SERIALIZATION_CONFIG: tsify::SerializationConfig = tsify::SerializationConfig { + missing_as_null: false, + hashmap_as_object: false, + large_number_types_as_bigints: false, + }; + } + #[automatically_derived] + impl> WasmDescribe for GenericAssoc { + #[inline] + fn describe() { + ::JsType::describe() + } + } + #[automatically_derived] + impl> WasmDescribeVector for GenericAssoc { + #[inline] + fn describe_vector() { + ::JsType::describe_vector() + } + } + #[automatically_derived] + impl> IntoWasmAbi for &GenericAssoc + where + GenericAssoc: _serde::Serialize, + { + type Abi = ::Abi; + #[inline] + fn into_abi(self) -> Self::Abi { + match self.into_js() { + Ok(js) => js.into_abi(), + Err(err) => { + let loc = core::panic::Location::caller(); + let msg = ::alloc::__export::must_use({ + ::alloc::fmt::format( + format_args!( + "(Converting type failed) {0} ({1}:{2}:{3})", err, loc + .file(), loc.line(), loc.column(), + ), + ) + }); + { + ::core::panicking::panic_display(&msg); + }; + } + } + } + } + #[automatically_derived] + impl> IntoWasmAbi for GenericAssoc + where + GenericAssoc: _serde::Serialize, + { + type Abi = ::Abi; + #[inline] + fn into_abi(self) -> Self::Abi { + (&self).into_abi() + } + } + #[automatically_derived] + impl> OptionIntoWasmAbi for GenericAssoc + where + GenericAssoc: _serde::Serialize, + { + #[inline] + fn none() -> Self::Abi { + ::none() + } + } + #[automatically_derived] + impl> From> for JsValue + where + GenericAssoc: _serde::Serialize, + { + #[inline] + fn from(value: GenericAssoc) -> Self { + match value.into_js() { + Ok(js) => js.into(), + Err(err) => { + let loc = core::panic::Location::caller(); + let msg = ::alloc::__export::must_use({ + ::alloc::fmt::format( + format_args!( + "(Converting type failed) {0} ({1}:{2}:{3})", err, loc + .file(), loc.line(), loc.column(), + ), + ) + }); + { + ::core::panicking::panic_display(&msg); + }; + } + } + } + } + #[automatically_derived] + impl> VectorIntoWasmAbi for GenericAssoc + where + GenericAssoc: _serde::Serialize, + { + type Abi = ::Abi; + #[inline] + fn vector_into_abi(vector: Box<[Self]>) -> Self::Abi { + let values = vector + .iter() + .map(|value| match value.into_js() { + Ok(js) => js.into(), + Err(err) => { + let loc = core::panic::Location::caller(); + let msg = ::alloc::__export::must_use({ + ::alloc::fmt::format( + format_args!( + "(Converting type failed) {0} ({1}:{2}:{3})", err, loc + .file(), loc.line(), loc.column(), + ), + ) + }); + { + ::core::panicking::panic_display(&msg); + }; + } + }) + .collect(); + JsValue::vector_into_abi(values) + } + } + #[automatically_derived] + impl> FromWasmAbi for GenericAssoc + where + Self: _serde::de::DeserializeOwned, + { + type Abi = ::Abi; + #[inline] + unsafe fn from_abi(js: Self::Abi) -> Self { + let result = Self::from_js(&JsType::from_abi(js)); + if let Err(err) = result { + wasm_bindgen::throw_str(err.to_string().as_ref()); + } + result.unwrap_throw() + } + } + #[automatically_derived] + impl> OptionFromWasmAbi for GenericAssoc + where + Self: _serde::de::DeserializeOwned, + { + #[inline] + fn is_none(js: &Self::Abi) -> bool { + ::is_none(js) + } + } + pub struct SelfOwner(T); + #[automatically_derived] + impl ::core::ops::Deref for SelfOwner { + type Target = T; + fn deref(&self) -> &Self::Target { + &self.0 + } + } + #[automatically_derived] + impl> RefFromWasmAbi for GenericAssoc + where + Self: _serde::de::DeserializeOwned, + { + type Abi = ::Abi; + type Anchor = SelfOwner; + unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor { + let result = Self::from_js(&*JsType::ref_from_abi(js)); + if let Err(err) = result { + wasm_bindgen::throw_str(err.to_string().as_ref()); + } + SelfOwner(result.unwrap_throw()) + } + } + #[automatically_derived] + impl> VectorFromWasmAbi for GenericAssoc + where + Self: _serde::de::DeserializeOwned, + { + type Abi = ::Abi; + #[inline] + unsafe fn vector_from_abi(js: Self::Abi) -> Box<[Self]> { + JsValue::vector_from_abi(js) + .into_iter() + .map(|value| { + let result = Self::from_js(value); + if let Err(err) = result { + wasm_bindgen::throw_str(err.to_string().as_ref()); + } + result.unwrap_throw() + }) + .collect() + } + } + #[allow(non_upper_case_globals)] + const _: () = { + #[deprecated( + note = "into_wasm_abi/from_wasm_abi are deprecated as they cause memory leaks (https://github.com/madonoharu/tsify/issues/65). Consider using `tsify::Ts` instead." + )] + const _x: () = (); + _x + }; +}; +#[tsify(into_wasm_abi, from_wasm_abi)] +pub struct GenericLifetime<'a: 'b, 'b> { + x: &'a str, + y: &'b str, +} +const _: () = { + extern crate serde as _serde; + use tsify::Tsify; + use wasm_bindgen::{ + convert::{ + FromWasmAbi, VectorFromWasmAbi, IntoWasmAbi, VectorIntoWasmAbi, + OptionFromWasmAbi, OptionIntoWasmAbi, RefFromWasmAbi, + }, + describe::WasmDescribe, describe::WasmDescribeVector, prelude::*, + }; + #[repr(transparent)] + pub struct JsType { + obj: wasm_bindgen::JsValue, + } + #[automatically_derived] + impl ::core::clone::Clone for JsType { + #[inline] + fn clone(&self) -> JsType { + JsType { + obj: ::core::clone::Clone::clone(&self.obj), + } + } + } + #[automatically_derived] + const _: () = { + use wasm_bindgen::convert::TryFromJsValue; + use wasm_bindgen::convert::{IntoWasmAbi, FromWasmAbi}; + use wasm_bindgen::convert::{OptionIntoWasmAbi, OptionFromWasmAbi}; + use wasm_bindgen::convert::{RefFromWasmAbi, LongRefFromWasmAbi}; + use wasm_bindgen::describe::WasmDescribe; + use wasm_bindgen::{JsValue, JsCast}; + use wasm_bindgen::__rt::{core, marker::ErasableGeneric}; + #[automatically_derived] + impl WasmDescribe for JsType { + fn describe() { + use wasm_bindgen::describe::*; + inform(NAMED_EXTERNREF); + inform(15u32); + inform(71u32); + inform(101u32); + inform(110u32); + inform(101u32); + inform(114u32); + inform(105u32); + inform(99u32); + inform(76u32); + inform(105u32); + inform(102u32); + inform(101u32); + inform(116u32); + inform(105u32); + inform(109u32); + inform(101u32); + } + } + #[automatically_derived] + impl IntoWasmAbi for JsType { + type Abi = ::Abi; + #[inline] + fn into_abi(self) -> Self::Abi { + self.obj.into_abi() + } + } + #[automatically_derived] + impl OptionIntoWasmAbi for JsType { + #[inline] + fn none() -> Self::Abi { + 0 + } + } + #[automatically_derived] + impl<'a> OptionIntoWasmAbi for &'a JsType { + #[inline] + fn none() -> Self::Abi { + 0 + } + } + #[automatically_derived] + impl FromWasmAbi for JsType { + type Abi = ::Abi; + #[inline] + unsafe fn from_abi(js: Self::Abi) -> Self { + JsType { + obj: JsValue::from_abi(js).into(), + } + } + } + #[automatically_derived] + impl OptionFromWasmAbi for JsType { + #[inline] + fn is_none(abi: &Self::Abi) -> bool { + *abi == 0 + } + } + #[automatically_derived] + impl<'a> IntoWasmAbi for &'a JsType { + type Abi = <&'a JsValue as IntoWasmAbi>::Abi; + #[inline] + fn into_abi(self) -> Self::Abi { + (&self.obj).into_abi() + } + } + #[automatically_derived] + impl RefFromWasmAbi for JsType { + type Abi = ::Abi; + type Anchor = wasm_bindgen::__rt::core::mem::ManuallyDrop; + #[inline] + unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor { + let tmp = ::ref_from_abi(js); + wasm_bindgen::__rt::core::mem::ManuallyDrop::new(JsType { + obj: wasm_bindgen::__rt::core::mem::ManuallyDrop::into_inner(tmp) + .into(), + }) + } + } + #[automatically_derived] + impl LongRefFromWasmAbi for JsType { + type Abi = ::Abi; + type Anchor = JsType; + #[inline] + unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor { + let tmp = ::long_ref_from_abi(js); + JsType { obj: tmp.into() } + } + } + #[automatically_derived] + impl AsRef for JsType { + #[inline] + fn as_ref(&self) -> &JsValue { + self.obj.as_ref() + } + } + #[automatically_derived] + impl AsRef for JsType { + #[inline] + fn as_ref(&self) -> &JsType { + self + } + } + #[automatically_derived] + impl wasm_bindgen::IntoJsGeneric for JsType + where + JsType: wasm_bindgen::JsGeneric, + { + type JsCanon = JsType; + #[inline] + fn to_js(self) -> JsType { + unsafe { + wasm_bindgen::__rt::core::mem::transmute_copy( + &wasm_bindgen::__rt::core::mem::ManuallyDrop::new(self), + ) + } + } + } + #[automatically_derived] + impl From for JsType { + #[inline] + fn from(obj: JsValue) -> Self { + JsType { obj: obj.into() } + } + } + #[automatically_derived] + impl From for JsValue { + #[inline] + fn from(obj: JsType) -> JsValue { + obj.obj.into() + } + } + #[automatically_derived] + impl JsCast for JsType { + fn instanceof(val: &JsValue) -> bool { + unsafe fn __wbg_instanceof_JsType_07a4c56f90e9a47b(_: u32) -> u32 { + { + ::core::panicking::panic_fmt( + format_args!("cannot check instanceof on non-wasm targets"), + ); + }; + } + unsafe { + let idx = val.into_abi(); + __wbg_instanceof_JsType_07a4c56f90e9a47b(idx) != 0 + } + } + #[inline] + fn unchecked_from_js(val: JsValue) -> Self { + JsType { obj: val.into() } + } + #[inline] + fn unchecked_from_js_ref(val: &JsValue) -> &Self { + unsafe { &*(val as *const JsValue as *const Self) } + } + } + unsafe impl ErasableGeneric for JsType { + type Repr = JsValue; + } + }; + #[automatically_derived] + impl wasm_bindgen::sys::Promising for JsType { + type Resolution = JsType; + } + #[automatically_derived] + impl wasm_bindgen::__rt::core::ops::Deref for JsType { + type Target = wasm_bindgen::JsValue; + #[inline] + fn deref(&self) -> &wasm_bindgen::JsValue { + &self.obj + } + } + #[automatically_derived] + impl wasm_bindgen::convert::UpcastFrom for wasm_bindgen::JsValue {} + #[automatically_derived] + impl wasm_bindgen::convert::UpcastFrom + for wasm_bindgen::sys::JsOption {} + #[automatically_derived] + impl wasm_bindgen::convert::UpcastFrom + for wasm_bindgen::sys::JsNullable {} + #[automatically_derived] + impl wasm_bindgen::convert::UpcastFrom for JsType {} + #[automatically_derived] + impl wasm_bindgen::convert::UpcastFrom + for wasm_bindgen::sys::JsOption {} + #[automatically_derived] + impl wasm_bindgen::convert::UpcastFrom + for wasm_bindgen::sys::JsNullable {} + #[automatically_derived] + impl<'a: 'b, 'b> Tsify for GenericLifetime<'a, 'b> { + type JsType = JsType; + const DECL: &'static str = "export interface GenericLifetime {\n x: string;\n y: string;\n}"; + const SERIALIZATION_CONFIG: tsify::SerializationConfig = tsify::SerializationConfig { + missing_as_null: false, + hashmap_as_object: false, + large_number_types_as_bigints: false, + }; + } + #[automatically_derived] + impl<'a: 'b, 'b> WasmDescribe for GenericLifetime<'a, 'b> { + #[inline] + fn describe() { + ::JsType::describe() + } + } + #[automatically_derived] + impl<'a: 'b, 'b> WasmDescribeVector for GenericLifetime<'a, 'b> { + #[inline] + fn describe_vector() { + ::JsType::describe_vector() + } + } + #[automatically_derived] + impl<'a: 'b, 'b> IntoWasmAbi for &GenericLifetime<'a, 'b> + where + GenericLifetime<'a, 'b>: _serde::Serialize, + { + type Abi = ::Abi; + #[inline] + fn into_abi(self) -> Self::Abi { + match self.into_js() { + Ok(js) => js.into_abi(), + Err(err) => { + let loc = core::panic::Location::caller(); + let msg = ::alloc::__export::must_use({ + ::alloc::fmt::format( + format_args!( + "(Converting type failed) {0} ({1}:{2}:{3})", err, loc + .file(), loc.line(), loc.column(), + ), + ) + }); + { + ::core::panicking::panic_display(&msg); + }; + } + } + } + } + #[automatically_derived] + impl<'a: 'b, 'b> IntoWasmAbi for GenericLifetime<'a, 'b> + where + GenericLifetime<'a, 'b>: _serde::Serialize, + { + type Abi = ::Abi; + #[inline] + fn into_abi(self) -> Self::Abi { + (&self).into_abi() + } + } + #[automatically_derived] + impl<'a: 'b, 'b> OptionIntoWasmAbi for GenericLifetime<'a, 'b> + where + GenericLifetime<'a, 'b>: _serde::Serialize, + { + #[inline] + fn none() -> Self::Abi { + ::none() + } + } + #[automatically_derived] + impl<'a: 'b, 'b> From> for JsValue + where + GenericLifetime<'a, 'b>: _serde::Serialize, + { + #[inline] + fn from(value: GenericLifetime<'a, 'b>) -> Self { + match value.into_js() { + Ok(js) => js.into(), + Err(err) => { + let loc = core::panic::Location::caller(); + let msg = ::alloc::__export::must_use({ + ::alloc::fmt::format( + format_args!( + "(Converting type failed) {0} ({1}:{2}:{3})", err, loc + .file(), loc.line(), loc.column(), + ), + ) + }); + { + ::core::panicking::panic_display(&msg); + }; + } + } + } + } + #[automatically_derived] + impl<'a: 'b, 'b> VectorIntoWasmAbi for GenericLifetime<'a, 'b> + where + GenericLifetime<'a, 'b>: _serde::Serialize, + { + type Abi = ::Abi; + #[inline] + fn vector_into_abi(vector: Box<[Self]>) -> Self::Abi { + let values = vector + .iter() + .map(|value| match value.into_js() { + Ok(js) => js.into(), + Err(err) => { + let loc = core::panic::Location::caller(); + let msg = ::alloc::__export::must_use({ + ::alloc::fmt::format( + format_args!( + "(Converting type failed) {0} ({1}:{2}:{3})", err, loc + .file(), loc.line(), loc.column(), + ), + ) + }); + { + ::core::panicking::panic_display(&msg); + }; + } + }) + .collect(); + JsValue::vector_into_abi(values) + } + } + #[automatically_derived] + impl<'a: 'b, 'b> FromWasmAbi for GenericLifetime<'a, 'b> + where + Self: _serde::de::DeserializeOwned, + { + type Abi = ::Abi; + #[inline] + unsafe fn from_abi(js: Self::Abi) -> Self { + let result = Self::from_js(&JsType::from_abi(js)); + if let Err(err) = result { + wasm_bindgen::throw_str(err.to_string().as_ref()); + } + result.unwrap_throw() + } + } + #[automatically_derived] + impl<'a: 'b, 'b> OptionFromWasmAbi for GenericLifetime<'a, 'b> + where + Self: _serde::de::DeserializeOwned, + { + #[inline] + fn is_none(js: &Self::Abi) -> bool { + ::is_none(js) + } + } + pub struct SelfOwner(T); + #[automatically_derived] + impl ::core::ops::Deref for SelfOwner { + type Target = T; + fn deref(&self) -> &Self::Target { + &self.0 + } + } + #[automatically_derived] + impl<'a: 'b, 'b> RefFromWasmAbi for GenericLifetime<'a, 'b> + where + Self: _serde::de::DeserializeOwned, + { + type Abi = ::Abi; + type Anchor = SelfOwner; + unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor { + let result = Self::from_js(&*JsType::ref_from_abi(js)); + if let Err(err) = result { + wasm_bindgen::throw_str(err.to_string().as_ref()); + } + SelfOwner(result.unwrap_throw()) + } + } + #[automatically_derived] + impl<'a: 'b, 'b> VectorFromWasmAbi for GenericLifetime<'a, 'b> + where + Self: _serde::de::DeserializeOwned, + { + type Abi = ::Abi; + #[inline] + unsafe fn vector_from_abi(js: Self::Abi) -> Box<[Self]> { + JsValue::vector_from_abi(js) + .into_iter() + .map(|value| { + let result = Self::from_js(value); + if let Err(err) = result { + wasm_bindgen::throw_str(err.to_string().as_ref()); + } + result.unwrap_throw() + }) + .collect() + } + } + #[allow(non_upper_case_globals)] + const _: () = { + #[deprecated( + note = "into_wasm_abi/from_wasm_abi are deprecated as they cause memory leaks (https://github.com/madonoharu/tsify/issues/65). Consider using `tsify::Ts` instead." + )] + const _x: () = (); + _x + }; +}; +#[tsify(into_wasm_abi, from_wasm_abi)] +pub struct GenericConst { + x: u32, +} +const _: () = { + extern crate serde as _serde; + use tsify::Tsify; + use wasm_bindgen::{ + convert::{ + FromWasmAbi, VectorFromWasmAbi, IntoWasmAbi, VectorIntoWasmAbi, + OptionFromWasmAbi, OptionIntoWasmAbi, RefFromWasmAbi, + }, + describe::WasmDescribe, describe::WasmDescribeVector, prelude::*, + }; + #[repr(transparent)] + pub struct JsType { + obj: wasm_bindgen::JsValue, + } + #[automatically_derived] + impl ::core::clone::Clone for JsType { + #[inline] + fn clone(&self) -> JsType { + JsType { + obj: ::core::clone::Clone::clone(&self.obj), + } + } + } + #[automatically_derived] + const _: () = { + use wasm_bindgen::convert::TryFromJsValue; + use wasm_bindgen::convert::{IntoWasmAbi, FromWasmAbi}; + use wasm_bindgen::convert::{OptionIntoWasmAbi, OptionFromWasmAbi}; + use wasm_bindgen::convert::{RefFromWasmAbi, LongRefFromWasmAbi}; + use wasm_bindgen::describe::WasmDescribe; + use wasm_bindgen::{JsValue, JsCast}; + use wasm_bindgen::__rt::{core, marker::ErasableGeneric}; + #[automatically_derived] + impl WasmDescribe for JsType { + fn describe() { + use wasm_bindgen::describe::*; + inform(NAMED_EXTERNREF); + inform(12u32); + inform(71u32); + inform(101u32); + inform(110u32); + inform(101u32); + inform(114u32); + inform(105u32); + inform(99u32); + inform(67u32); + inform(111u32); + inform(110u32); + inform(115u32); + inform(116u32); + } + } + #[automatically_derived] + impl IntoWasmAbi for JsType { + type Abi = ::Abi; + #[inline] + fn into_abi(self) -> Self::Abi { + self.obj.into_abi() + } + } + #[automatically_derived] + impl OptionIntoWasmAbi for JsType { + #[inline] + fn none() -> Self::Abi { + 0 + } + } + #[automatically_derived] + impl<'a> OptionIntoWasmAbi for &'a JsType { + #[inline] + fn none() -> Self::Abi { + 0 + } + } + #[automatically_derived] + impl FromWasmAbi for JsType { + type Abi = ::Abi; + #[inline] + unsafe fn from_abi(js: Self::Abi) -> Self { + JsType { + obj: JsValue::from_abi(js).into(), + } + } + } + #[automatically_derived] + impl OptionFromWasmAbi for JsType { + #[inline] + fn is_none(abi: &Self::Abi) -> bool { + *abi == 0 + } + } + #[automatically_derived] + impl<'a> IntoWasmAbi for &'a JsType { + type Abi = <&'a JsValue as IntoWasmAbi>::Abi; + #[inline] + fn into_abi(self) -> Self::Abi { + (&self.obj).into_abi() + } + } + #[automatically_derived] + impl RefFromWasmAbi for JsType { + type Abi = ::Abi; + type Anchor = wasm_bindgen::__rt::core::mem::ManuallyDrop; + #[inline] + unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor { + let tmp = ::ref_from_abi(js); + wasm_bindgen::__rt::core::mem::ManuallyDrop::new(JsType { + obj: wasm_bindgen::__rt::core::mem::ManuallyDrop::into_inner(tmp) + .into(), + }) + } + } + #[automatically_derived] + impl LongRefFromWasmAbi for JsType { + type Abi = ::Abi; + type Anchor = JsType; + #[inline] + unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor { + let tmp = ::long_ref_from_abi(js); + JsType { obj: tmp.into() } + } + } + #[automatically_derived] + impl AsRef for JsType { + #[inline] + fn as_ref(&self) -> &JsValue { + self.obj.as_ref() + } + } + #[automatically_derived] + impl AsRef for JsType { + #[inline] + fn as_ref(&self) -> &JsType { + self + } + } + #[automatically_derived] + impl wasm_bindgen::IntoJsGeneric for JsType + where + JsType: wasm_bindgen::JsGeneric, + { + type JsCanon = JsType; + #[inline] + fn to_js(self) -> JsType { + unsafe { + wasm_bindgen::__rt::core::mem::transmute_copy( + &wasm_bindgen::__rt::core::mem::ManuallyDrop::new(self), + ) + } + } + } + #[automatically_derived] + impl From for JsType { + #[inline] + fn from(obj: JsValue) -> Self { + JsType { obj: obj.into() } + } + } + #[automatically_derived] + impl From for JsValue { + #[inline] + fn from(obj: JsType) -> JsValue { + obj.obj.into() + } + } + #[automatically_derived] + impl JsCast for JsType { + fn instanceof(val: &JsValue) -> bool { + unsafe fn __wbg_instanceof_JsType_07a4c56f90e9a47b(_: u32) -> u32 { + { + ::core::panicking::panic_fmt( + format_args!("cannot check instanceof on non-wasm targets"), + ); + }; + } + unsafe { + let idx = val.into_abi(); + __wbg_instanceof_JsType_07a4c56f90e9a47b(idx) != 0 + } + } + #[inline] + fn unchecked_from_js(val: JsValue) -> Self { + JsType { obj: val.into() } + } + #[inline] + fn unchecked_from_js_ref(val: &JsValue) -> &Self { + unsafe { &*(val as *const JsValue as *const Self) } + } + } + unsafe impl ErasableGeneric for JsType { + type Repr = JsValue; + } + }; + #[automatically_derived] + impl wasm_bindgen::sys::Promising for JsType { + type Resolution = JsType; + } + #[automatically_derived] + impl wasm_bindgen::__rt::core::ops::Deref for JsType { + type Target = wasm_bindgen::JsValue; + #[inline] + fn deref(&self) -> &wasm_bindgen::JsValue { + &self.obj + } + } + #[automatically_derived] + impl wasm_bindgen::convert::UpcastFrom for wasm_bindgen::JsValue {} + #[automatically_derived] + impl wasm_bindgen::convert::UpcastFrom + for wasm_bindgen::sys::JsOption {} + #[automatically_derived] + impl wasm_bindgen::convert::UpcastFrom + for wasm_bindgen::sys::JsNullable {} + #[automatically_derived] + impl wasm_bindgen::convert::UpcastFrom for JsType {} + #[automatically_derived] + impl wasm_bindgen::convert::UpcastFrom + for wasm_bindgen::sys::JsOption {} + #[automatically_derived] + impl wasm_bindgen::convert::UpcastFrom + for wasm_bindgen::sys::JsNullable {} + #[automatically_derived] + impl Tsify for GenericConst { + type JsType = JsType; + const DECL: &'static str = "export interface GenericConst {\n x: number;\n}"; + const SERIALIZATION_CONFIG: tsify::SerializationConfig = tsify::SerializationConfig { + missing_as_null: false, + hashmap_as_object: false, + large_number_types_as_bigints: false, + }; + } + #[automatically_derived] + impl WasmDescribe for GenericConst { + #[inline] + fn describe() { + ::JsType::describe() + } + } + #[automatically_derived] + impl WasmDescribeVector for GenericConst { + #[inline] + fn describe_vector() { + ::JsType::describe_vector() + } + } + #[automatically_derived] + impl IntoWasmAbi for &GenericConst + where + GenericConst: _serde::Serialize, + { + type Abi = ::Abi; + #[inline] + fn into_abi(self) -> Self::Abi { + match self.into_js() { + Ok(js) => js.into_abi(), + Err(err) => { + let loc = core::panic::Location::caller(); + let msg = ::alloc::__export::must_use({ + ::alloc::fmt::format( + format_args!( + "(Converting type failed) {0} ({1}:{2}:{3})", err, loc + .file(), loc.line(), loc.column(), + ), + ) + }); + { + ::core::panicking::panic_display(&msg); + }; + } + } + } + } + #[automatically_derived] + impl IntoWasmAbi for GenericConst + where + GenericConst: _serde::Serialize, + { + type Abi = ::Abi; + #[inline] + fn into_abi(self) -> Self::Abi { + (&self).into_abi() + } + } + #[automatically_derived] + impl OptionIntoWasmAbi for GenericConst + where + GenericConst: _serde::Serialize, + { + #[inline] + fn none() -> Self::Abi { + ::none() + } + } + #[automatically_derived] + impl From> for JsValue + where + GenericConst: _serde::Serialize, + { + #[inline] + fn from(value: GenericConst) -> Self { + match value.into_js() { + Ok(js) => js.into(), + Err(err) => { + let loc = core::panic::Location::caller(); + let msg = ::alloc::__export::must_use({ + ::alloc::fmt::format( + format_args!( + "(Converting type failed) {0} ({1}:{2}:{3})", err, loc + .file(), loc.line(), loc.column(), + ), + ) + }); + { + ::core::panicking::panic_display(&msg); + }; + } + } + } + } + #[automatically_derived] + impl VectorIntoWasmAbi for GenericConst + where + GenericConst: _serde::Serialize, + { + type Abi = ::Abi; + #[inline] + fn vector_into_abi(vector: Box<[Self]>) -> Self::Abi { + let values = vector + .iter() + .map(|value| match value.into_js() { + Ok(js) => js.into(), + Err(err) => { + let loc = core::panic::Location::caller(); + let msg = ::alloc::__export::must_use({ + ::alloc::fmt::format( + format_args!( + "(Converting type failed) {0} ({1}:{2}:{3})", err, loc + .file(), loc.line(), loc.column(), + ), + ) + }); + { + ::core::panicking::panic_display(&msg); + }; + } + }) + .collect(); + JsValue::vector_into_abi(values) + } + } + #[automatically_derived] + impl FromWasmAbi for GenericConst + where + Self: _serde::de::DeserializeOwned, + { + type Abi = ::Abi; + #[inline] + unsafe fn from_abi(js: Self::Abi) -> Self { + let result = Self::from_js(&JsType::from_abi(js)); + if let Err(err) = result { + wasm_bindgen::throw_str(err.to_string().as_ref()); + } + result.unwrap_throw() + } + } + #[automatically_derived] + impl OptionFromWasmAbi for GenericConst + where + Self: _serde::de::DeserializeOwned, + { + #[inline] + fn is_none(js: &Self::Abi) -> bool { + ::is_none(js) + } + } + pub struct SelfOwner(T); + #[automatically_derived] + impl ::core::ops::Deref for SelfOwner { + type Target = T; + fn deref(&self) -> &Self::Target { + &self.0 + } + } + #[automatically_derived] + impl RefFromWasmAbi for GenericConst + where + Self: _serde::de::DeserializeOwned, + { + type Abi = ::Abi; + type Anchor = SelfOwner; + unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor { + let result = Self::from_js(&*JsType::ref_from_abi(js)); + if let Err(err) = result { + wasm_bindgen::throw_str(err.to_string().as_ref()); + } + SelfOwner(result.unwrap_throw()) + } + } + #[automatically_derived] + impl VectorFromWasmAbi for GenericConst + where + Self: _serde::de::DeserializeOwned, + { + type Abi = ::Abi; + #[inline] + unsafe fn vector_from_abi(js: Self::Abi) -> Box<[Self]> { + JsValue::vector_from_abi(js) + .into_iter() + .map(|value| { + let result = Self::from_js(value); + if let Err(err) = result { + wasm_bindgen::throw_str(err.to_string().as_ref()); + } + result.unwrap_throw() + }) + .collect() + } + } + #[allow(non_upper_case_globals)] + const _: () = { + #[deprecated( + note = "into_wasm_abi/from_wasm_abi are deprecated as they cause memory leaks (https://github.com/madonoharu/tsify/issues/65). Consider using `tsify::Ts` instead." + )] + const _x: () = (); + _x + }; +}; diff --git a/tests/expand/generic_constrained_struct.rs b/tests/expand/generic_constrained_struct.rs new file mode 100644 index 0000000..081433f --- /dev/null +++ b/tests/expand/generic_constrained_struct.rs @@ -0,0 +1,32 @@ +use tsify::Tsify; + +pub trait Constraint {} + +#[derive(Tsify)] +#[tsify(into_wasm_abi, from_wasm_abi)] +pub struct GenericStruct { + x: T, +} + +#[derive(Tsify)] +#[tsify(into_wasm_abi, from_wasm_abi)] +pub struct GenericNewtype(T); + +#[derive(Tsify)] +#[tsify(into_wasm_abi, from_wasm_abi)] +pub struct GenericAssoc> { + x: T, +} + +#[derive(Tsify)] +#[tsify(into_wasm_abi, from_wasm_abi)] +pub struct GenericLifetime<'a: 'b, 'b> { + x: &'a str, + y: &'b str, +} + +#[derive(Tsify)] +#[tsify(into_wasm_abi, from_wasm_abi)] +pub struct GenericConst { + x: u32, +} diff --git a/tsify-macros/src/wasm_bindgen.rs b/tsify-macros/src/wasm_bindgen.rs index 899acf5..d87b27c 100644 --- a/tsify-macros/src/wasm_bindgen.rs +++ b/tsify-macros/src/wasm_bindgen.rs @@ -117,12 +117,14 @@ fn expand_into_wasm_abi(cont: &Container) -> TokenStream { let ident = cont.ident(); let serde_path = cont.serde_container.attrs.serde_path(); let mut generics = cont.generics_without_defaults(); - let borrowed_generics = generics.clone(); - generics - .make_where_clause() - .predicates - .push(parse_quote!(#ident #borrowed_generics: #serde_path::Serialize)); + // A predicate's self type is a type position, where `Generics` would render + // its declaration form — bounds, defaults, `const N: usize` — and hit E0229. + let predicate: syn::WherePredicate = { + let (_, ty_generics, _) = generics.split_for_impl(); + parse_quote!(#ident #ty_generics: #serde_path::Serialize) + }; + generics.make_where_clause().predicates.push(predicate); let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();