generic_struct.expanded.rs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. use tsify::Tsify;
  2. #[tsify(into_wasm_abi, from_wasm_abi)]
  3. pub struct GenericStruct<T> {
  4. x: T,
  5. }
  6. #[automatically_derived]
  7. const _: () = {
  8. extern crate serde as _serde;
  9. use tsify::Tsify;
  10. use wasm_bindgen::{
  11. convert::{FromWasmAbi, IntoWasmAbi, OptionFromWasmAbi, OptionIntoWasmAbi},
  12. describe::WasmDescribe, prelude::*,
  13. };
  14. #[wasm_bindgen]
  15. extern "C" {
  16. #[wasm_bindgen(typescript_type = "GenericStruct")]
  17. pub type JsType;
  18. }
  19. impl<T> Tsify for GenericStruct<T> {
  20. type JsType = JsType;
  21. const DECL: &'static str = "export interface GenericStruct<T> {\n x: T;\n}";
  22. }
  23. #[wasm_bindgen(typescript_custom_section)]
  24. const TS_APPEND_CONTENT: &'static str = "export interface GenericStruct<T> {\n x: T;\n}";
  25. impl<T> WasmDescribe for GenericStruct<T> {
  26. #[inline]
  27. fn describe() {
  28. <Self as Tsify>::JsType::describe()
  29. }
  30. }
  31. impl<T> IntoWasmAbi for GenericStruct<T>
  32. where
  33. Self: _serde::Serialize,
  34. {
  35. type Abi = <JsType as IntoWasmAbi>::Abi;
  36. #[inline]
  37. fn into_abi(self) -> Self::Abi {
  38. self.into_js().unwrap_throw().into_abi()
  39. }
  40. }
  41. impl<T> OptionIntoWasmAbi for GenericStruct<T>
  42. where
  43. Self: _serde::Serialize,
  44. {
  45. #[inline]
  46. fn none() -> Self::Abi {
  47. <JsType as OptionIntoWasmAbi>::none()
  48. }
  49. }
  50. impl<T> FromWasmAbi for GenericStruct<T>
  51. where
  52. Self: _serde::de::DeserializeOwned,
  53. {
  54. type Abi = <JsType as FromWasmAbi>::Abi;
  55. #[inline]
  56. unsafe fn from_abi(js: Self::Abi) -> Self {
  57. let result = Self::from_js(&JsType::from_abi(js));
  58. if let Err(err) = result {
  59. wasm_bindgen::throw_str(err.to_string().as_ref());
  60. }
  61. result.unwrap_throw()
  62. }
  63. }
  64. impl<T> OptionFromWasmAbi for GenericStruct<T>
  65. where
  66. Self: _serde::de::DeserializeOwned,
  67. {
  68. #[inline]
  69. fn is_none(js: &Self::Abi) -> bool {
  70. <JsType as OptionFromWasmAbi>::is_none(js)
  71. }
  72. }
  73. };
  74. #[tsify(into_wasm_abi, from_wasm_abi)]
  75. pub struct GenericNewtype<T>(T);
  76. #[automatically_derived]
  77. const _: () = {
  78. extern crate serde as _serde;
  79. use tsify::Tsify;
  80. use wasm_bindgen::{
  81. convert::{FromWasmAbi, IntoWasmAbi, OptionFromWasmAbi, OptionIntoWasmAbi},
  82. describe::WasmDescribe, prelude::*,
  83. };
  84. #[wasm_bindgen]
  85. extern "C" {
  86. #[wasm_bindgen(typescript_type = "GenericNewtype")]
  87. pub type JsType;
  88. }
  89. impl<T> Tsify for GenericNewtype<T> {
  90. type JsType = JsType;
  91. const DECL: &'static str = "export type GenericNewtype<T> = T;";
  92. }
  93. #[wasm_bindgen(typescript_custom_section)]
  94. const TS_APPEND_CONTENT: &'static str = "export type GenericNewtype<T> = T;";
  95. impl<T> WasmDescribe for GenericNewtype<T> {
  96. #[inline]
  97. fn describe() {
  98. <Self as Tsify>::JsType::describe()
  99. }
  100. }
  101. impl<T> IntoWasmAbi for GenericNewtype<T>
  102. where
  103. Self: _serde::Serialize,
  104. {
  105. type Abi = <JsType as IntoWasmAbi>::Abi;
  106. #[inline]
  107. fn into_abi(self) -> Self::Abi {
  108. self.into_js().unwrap_throw().into_abi()
  109. }
  110. }
  111. impl<T> OptionIntoWasmAbi for GenericNewtype<T>
  112. where
  113. Self: _serde::Serialize,
  114. {
  115. #[inline]
  116. fn none() -> Self::Abi {
  117. <JsType as OptionIntoWasmAbi>::none()
  118. }
  119. }
  120. impl<T> FromWasmAbi for GenericNewtype<T>
  121. where
  122. Self: _serde::de::DeserializeOwned,
  123. {
  124. type Abi = <JsType as FromWasmAbi>::Abi;
  125. #[inline]
  126. unsafe fn from_abi(js: Self::Abi) -> Self {
  127. let result = Self::from_js(&JsType::from_abi(js));
  128. if let Err(err) = result {
  129. wasm_bindgen::throw_str(err.to_string().as_ref());
  130. }
  131. result.unwrap_throw()
  132. }
  133. }
  134. impl<T> OptionFromWasmAbi for GenericNewtype<T>
  135. where
  136. Self: _serde::de::DeserializeOwned,
  137. {
  138. #[inline]
  139. fn is_none(js: &Self::Abi) -> bool {
  140. <JsType as OptionFromWasmAbi>::is_none(js)
  141. }
  142. }
  143. };