| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- use tsify::Tsify;
- #[tsify(into_wasm_abi, from_wasm_abi)]
- pub struct GenericStruct<T> {
- x: T,
- }
- #[automatically_derived]
- const _: () = {
- extern crate serde as _serde;
- use tsify::Tsify;
- use wasm_bindgen::{
- convert::{FromWasmAbi, IntoWasmAbi, OptionFromWasmAbi, OptionIntoWasmAbi},
- describe::WasmDescribe, prelude::*,
- };
- #[wasm_bindgen]
- extern "C" {
- #[wasm_bindgen(typescript_type = "GenericStruct")]
- pub type JsType;
- }
- impl<T> Tsify for GenericStruct<T> {
- type JsType = JsType;
- const DECL: &'static str = "export interface GenericStruct<T> {\n x: T;\n}";
- }
- #[wasm_bindgen(typescript_custom_section)]
- const TS_APPEND_CONTENT: &'static str = "export interface GenericStruct<T> {\n x: T;\n}";
- impl<T> WasmDescribe for GenericStruct<T> {
- #[inline]
- fn describe() {
- <Self as Tsify>::JsType::describe()
- }
- }
- impl<T> IntoWasmAbi for GenericStruct<T>
- where
- Self: _serde::Serialize,
- {
- type Abi = <JsType as IntoWasmAbi>::Abi;
- #[inline]
- fn into_abi(self) -> Self::Abi {
- self.into_js().unwrap_throw().into_abi()
- }
- }
- impl<T> OptionIntoWasmAbi for GenericStruct<T>
- where
- Self: _serde::Serialize,
- {
- #[inline]
- fn none() -> Self::Abi {
- <JsType as OptionIntoWasmAbi>::none()
- }
- }
- impl<T> FromWasmAbi for GenericStruct<T>
- where
- Self: _serde::de::DeserializeOwned,
- {
- type Abi = <JsType as FromWasmAbi>::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()
- }
- }
- impl<T> OptionFromWasmAbi for GenericStruct<T>
- where
- Self: _serde::de::DeserializeOwned,
- {
- #[inline]
- fn is_none(js: &Self::Abi) -> bool {
- <JsType as OptionFromWasmAbi>::is_none(js)
- }
- }
- };
- #[tsify(into_wasm_abi, from_wasm_abi)]
- pub struct GenericNewtype<T>(T);
- #[automatically_derived]
- const _: () = {
- extern crate serde as _serde;
- use tsify::Tsify;
- use wasm_bindgen::{
- convert::{FromWasmAbi, IntoWasmAbi, OptionFromWasmAbi, OptionIntoWasmAbi},
- describe::WasmDescribe, prelude::*,
- };
- #[wasm_bindgen]
- extern "C" {
- #[wasm_bindgen(typescript_type = "GenericNewtype")]
- pub type JsType;
- }
- impl<T> Tsify for GenericNewtype<T> {
- type JsType = JsType;
- const DECL: &'static str = "export type GenericNewtype<T> = T;";
- }
- #[wasm_bindgen(typescript_custom_section)]
- const TS_APPEND_CONTENT: &'static str = "export type GenericNewtype<T> = T;";
- impl<T> WasmDescribe for GenericNewtype<T> {
- #[inline]
- fn describe() {
- <Self as Tsify>::JsType::describe()
- }
- }
- impl<T> IntoWasmAbi for GenericNewtype<T>
- where
- Self: _serde::Serialize,
- {
- type Abi = <JsType as IntoWasmAbi>::Abi;
- #[inline]
- fn into_abi(self) -> Self::Abi {
- self.into_js().unwrap_throw().into_abi()
- }
- }
- impl<T> OptionIntoWasmAbi for GenericNewtype<T>
- where
- Self: _serde::Serialize,
- {
- #[inline]
- fn none() -> Self::Abi {
- <JsType as OptionIntoWasmAbi>::none()
- }
- }
- impl<T> FromWasmAbi for GenericNewtype<T>
- where
- Self: _serde::de::DeserializeOwned,
- {
- type Abi = <JsType as FromWasmAbi>::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()
- }
- }
- impl<T> OptionFromWasmAbi for GenericNewtype<T>
- where
- Self: _serde::de::DeserializeOwned,
- {
- #[inline]
- fn is_none(js: &Self::Abi) -> bool {
- <JsType as OptionFromWasmAbi>::is_none(js)
- }
- }
- };
|