borrow.expanded.rs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. use std::borrow::Cow;
  2. use tsify::Tsify;
  3. #[tsify(into_wasm_abi, from_wasm_abi)]
  4. struct Borrow<'a> {
  5. raw: &'a str,
  6. cow: Cow<'a, str>,
  7. }
  8. #[automatically_derived]
  9. const _: () = {
  10. extern crate serde as _serde;
  11. use tsify::Tsify;
  12. use wasm_bindgen::{
  13. convert::{FromWasmAbi, IntoWasmAbi, OptionFromWasmAbi, OptionIntoWasmAbi},
  14. describe::WasmDescribe, prelude::*,
  15. };
  16. #[wasm_bindgen]
  17. extern "C" {
  18. #[wasm_bindgen(typescript_type = "Borrow")]
  19. pub type JsType;
  20. }
  21. impl<'a> Tsify for Borrow<'a> {
  22. type JsType = JsType;
  23. const DECL: &'static str = "export interface Borrow {\n raw: string;\n cow: string;\n}";
  24. }
  25. #[wasm_bindgen(typescript_custom_section)]
  26. const TS_APPEND_CONTENT: &'static str = "export interface Borrow {\n raw: string;\n cow: string;\n}";
  27. impl<'a> WasmDescribe for Borrow<'a> {
  28. #[inline]
  29. fn describe() {
  30. <Self as Tsify>::JsType::describe()
  31. }
  32. }
  33. impl<'a> IntoWasmAbi for Borrow<'a>
  34. where
  35. Self: _serde::Serialize,
  36. {
  37. type Abi = <JsType as IntoWasmAbi>::Abi;
  38. #[inline]
  39. fn into_abi(self) -> Self::Abi {
  40. self.into_js().unwrap_throw().into_abi()
  41. }
  42. }
  43. impl<'a> OptionIntoWasmAbi for Borrow<'a>
  44. where
  45. Self: _serde::Serialize,
  46. {
  47. #[inline]
  48. fn none() -> Self::Abi {
  49. <JsType as OptionIntoWasmAbi>::none()
  50. }
  51. }
  52. impl<'a> FromWasmAbi for Borrow<'a>
  53. where
  54. Self: _serde::de::DeserializeOwned,
  55. {
  56. type Abi = <JsType as FromWasmAbi>::Abi;
  57. #[inline]
  58. unsafe fn from_abi(js: Self::Abi) -> Self {
  59. let result = Self::from_js(&JsType::from_abi(js));
  60. if let Err(err) = result {
  61. wasm_bindgen::throw_str(err.to_string().as_ref());
  62. }
  63. result.unwrap_throw()
  64. }
  65. }
  66. impl<'a> OptionFromWasmAbi for Borrow<'a>
  67. where
  68. Self: _serde::de::DeserializeOwned,
  69. {
  70. #[inline]
  71. fn is_none(js: &Self::Abi) -> bool {
  72. <JsType as OptionFromWasmAbi>::is_none(js)
  73. }
  74. }
  75. };