bitwarden_ffi/
wire_macros.rs1#[macro_export]
12macro_rules! impl_wire_record {
13 ($ty:ty, input) => {
14 #[cfg(feature = "wasm")]
15 impl $crate::FromWasm for $ty {
16 type Wire = $crate::Ts<$ty>;
17
18 fn from_wire(wire: Self::Wire) -> ::core::result::Result<Self, $crate::WireError> {
19 wire.to_rust().map_err($crate::WireError::from)
20 }
21 }
22 };
23 ($ty:ty) => {
24 $crate::impl_wire_record!($ty, input);
25
26 #[cfg(feature = "wasm")]
27 impl $crate::ToWasm for $ty {
28 type Wire = $crate::Ts<$ty>;
29
30 fn to_wire(self) -> ::core::result::Result<Self::Wire, $crate::WireError> {
31 $crate::Ts::from_rust(&self).map_err($crate::WireError::from)
32 }
33 }
34 };
35}
36
37#[macro_export]
42macro_rules! impl_wire_object {
43 ($($ty:ty),* $(,)?) => {
44 $(
45 #[cfg(feature = "wasm")]
46 impl $crate::FromWasm for $ty {
47 type Wire = $ty;
48
49 fn from_wire(wire: Self::Wire) -> ::core::result::Result<Self, $crate::WireError> {
50 ::core::result::Result::Ok(wire)
51 }
52 }
53
54 #[cfg(feature = "wasm")]
55 impl $crate::ToWasm for $ty {
56 type Wire = $ty;
57
58 fn to_wire(self) -> ::core::result::Result<Self::Wire, $crate::WireError> {
59 ::core::result::Result::Ok(self)
60 }
61 }
62 )*
63 };
64}
65
66#[macro_export]
80macro_rules! impl_wire_string {
81 ($ty:ty $(,)?) => {
82 $crate::impl_wire_string!(
83 $ty,
84 parse = |wire: ::std::string::String| wire.parse::<$ty>(),
85 format = |value: $ty| ::std::string::ToString::to_string(&value),
86 );
87 };
88 ($ty:ty, parse = $parse:expr, format = $format:expr $(,)?) => {
89 $crate::impl_wire_string!($ty, parse = $parse);
90
91 #[cfg(feature = "wasm")]
92 impl $crate::ToWasm for $ty {
93 type Wire = ::std::string::String;
94
95 fn to_wire(self) -> ::core::result::Result<Self::Wire, $crate::WireError> {
96 ::core::result::Result::Ok($crate::format_wire_string(self, $format))
97 }
98 }
99
100 #[cfg(feature = "wasm")]
101 impl $crate::_macro::wasm_bindgen::convert::IntoWasmAbi for $ty {
102 type Abi =
103 <::std::string::String as $crate::_macro::wasm_bindgen::convert::IntoWasmAbi>::Abi;
104
105 fn into_abi(self) -> Self::Abi {
106 let wire = $crate::_macro::wasm_bindgen::UnwrapThrowExt::unwrap_throw(
107 <$ty as $crate::ToWasm>::to_wire(self),
108 );
109 $crate::_macro::wasm_bindgen::convert::IntoWasmAbi::into_abi(wire)
110 }
111 }
112
113 #[cfg(feature = "wasm")]
114 impl $crate::_macro::wasm_bindgen::convert::OptionIntoWasmAbi for $ty {
115 fn none() -> Self::Abi {
116 <::std::string::String as $crate::_macro::wasm_bindgen::convert::OptionIntoWasmAbi>::none()
117 }
118 }
119 };
120 ($ty:ty, parse = $parse:expr $(,)?) => {
121 #[cfg(feature = "wasm")]
122 impl $crate::FromWasm for $ty {
123 type Wire = ::std::string::String;
124
125 fn from_wire(wire: Self::Wire) -> ::core::result::Result<Self, $crate::WireError> {
126 $crate::parse_wire_string(stringify!($ty), wire, $parse)
127 }
128 }
129
130 #[cfg(feature = "wasm")]
131 impl $crate::_macro::wasm_bindgen::describe::WasmDescribe for $ty {
132 fn describe() {
133 <::std::string::String as $crate::_macro::wasm_bindgen::describe::WasmDescribe>::describe();
134 }
135 }
136 };
137}