diff --git a/tests/expand/borrow.expanded.rs b/tests/expand/borrow.expanded.rs index a5d6010..90373d0 100644 --- a/tests/expand/borrow.expanded.rs +++ b/tests/expand/borrow.expanded.rs @@ -12,7 +12,7 @@ const _: () = { use wasm_bindgen::{ convert::{ FromWasmAbi, IntoWasmAbi, OptionFromWasmAbi, OptionIntoWasmAbi, - RefFromWasmAbi, + RefFromWasmAbi, LongRefFromWasmAbi, }, describe::WasmDescribe, prelude::*, }; @@ -243,6 +243,11 @@ const _: () = { &self.0 } } + impl ::core::borrow::Borrow for SelfOwner { + fn borrow(&self) -> &T { + &self.0 + } + } impl<'a> RefFromWasmAbi for Borrow<'a> where Self: _serde::de::DeserializeOwned, @@ -257,4 +262,18 @@ const _: () = { SelfOwner(result.unwrap_throw()) } } + impl<'a> LongRefFromWasmAbi for Borrow<'a> + where + Self: _serde::de::DeserializeOwned, + { + type Abi = ::Abi; + type Anchor = SelfOwner; + unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor { + let result = Self::from_js(&JsType::from_abi(js)); + if let Err(err) = result { + wasm_bindgen::throw_str(err.to_string().as_ref()); + } + SelfOwner(result.unwrap_throw()) + } + } }; diff --git a/tests/expand/generic_enum.expanded.rs b/tests/expand/generic_enum.expanded.rs index b7a4dd6..a3c4312 100644 --- a/tests/expand/generic_enum.expanded.rs +++ b/tests/expand/generic_enum.expanded.rs @@ -13,7 +13,7 @@ const _: () = { use wasm_bindgen::{ convert::{ FromWasmAbi, IntoWasmAbi, OptionFromWasmAbi, OptionIntoWasmAbi, - RefFromWasmAbi, + RefFromWasmAbi, LongRefFromWasmAbi, }, describe::WasmDescribe, prelude::*, }; @@ -249,6 +249,11 @@ const _: () = { &self.0 } } + impl ::core::borrow::Borrow for SelfOwner { + fn borrow(&self) -> &T { + &self.0 + } + } impl RefFromWasmAbi for GenericEnum where Self: _serde::de::DeserializeOwned, @@ -263,4 +268,18 @@ const _: () = { SelfOwner(result.unwrap_throw()) } } + impl LongRefFromWasmAbi for GenericEnum + where + Self: _serde::de::DeserializeOwned, + { + type Abi = ::Abi; + type Anchor = SelfOwner; + unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor { + let result = Self::from_js(&JsType::from_abi(js)); + if let Err(err) = result { + wasm_bindgen::throw_str(err.to_string().as_ref()); + } + SelfOwner(result.unwrap_throw()) + } + } }; diff --git a/tests/expand/generic_struct.expanded.rs b/tests/expand/generic_struct.expanded.rs index 71bfa9e..3348544 100644 --- a/tests/expand/generic_struct.expanded.rs +++ b/tests/expand/generic_struct.expanded.rs @@ -10,7 +10,7 @@ const _: () = { use wasm_bindgen::{ convert::{ FromWasmAbi, IntoWasmAbi, OptionFromWasmAbi, OptionIntoWasmAbi, - RefFromWasmAbi, + RefFromWasmAbi, LongRefFromWasmAbi, }, describe::WasmDescribe, prelude::*, }; @@ -248,6 +248,11 @@ const _: () = { &self.0 } } + impl ::core::borrow::Borrow for SelfOwner { + fn borrow(&self) -> &T { + &self.0 + } + } impl RefFromWasmAbi for GenericStruct where Self: _serde::de::DeserializeOwned, @@ -262,6 +267,20 @@ const _: () = { SelfOwner(result.unwrap_throw()) } } + impl LongRefFromWasmAbi for GenericStruct + where + Self: _serde::de::DeserializeOwned, + { + type Abi = ::Abi; + type Anchor = SelfOwner; + unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor { + let result = Self::from_js(&JsType::from_abi(js)); + if let Err(err) = result { + wasm_bindgen::throw_str(err.to_string().as_ref()); + } + SelfOwner(result.unwrap_throw()) + } + } }; #[tsify(into_wasm_abi, from_wasm_abi)] pub struct GenericNewtype(T); @@ -272,7 +291,7 @@ const _: () = { use wasm_bindgen::{ convert::{ FromWasmAbi, IntoWasmAbi, OptionFromWasmAbi, OptionIntoWasmAbi, - RefFromWasmAbi, + RefFromWasmAbi, LongRefFromWasmAbi, }, describe::WasmDescribe, prelude::*, }; @@ -511,6 +530,11 @@ const _: () = { &self.0 } } + impl ::core::borrow::Borrow for SelfOwner { + fn borrow(&self) -> &T { + &self.0 + } + } impl RefFromWasmAbi for GenericNewtype where Self: _serde::de::DeserializeOwned, @@ -525,4 +549,18 @@ const _: () = { SelfOwner(result.unwrap_throw()) } } + impl LongRefFromWasmAbi for GenericNewtype + where + Self: _serde::de::DeserializeOwned, + { + type Abi = ::Abi; + type Anchor = SelfOwner; + unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor { + let result = Self::from_js(&JsType::from_abi(js)); + if let Err(err) = result { + wasm_bindgen::throw_str(err.to_string().as_ref()); + } + SelfOwner(result.unwrap_throw()) + } + } };