Skip to main content

wasm_bindgen/convert/
mod.rs

1//! # ⚠️ Unstable
2//!
3//! This is an internal module, no stability guarantees are provided. Use at
4//! your own risk.
5
6#![allow(clippy::missing_safety_doc)]
7
8/// `NullableIntoWasmAbi` for a type whose own ABI has a spare value for
9/// `Null` beside its `OptionIntoWasmAbi::none`, so `Nullable<Self>` shares
10/// that ABI as `Option<Self>` does.
11macro_rules! impl_nullable_into_shared_abi {
12    (null = $null:expr; [$($g:tt)*] $t:ty $(where $($w:tt)*)?) => {
13        impl<$($g)*> $crate::convert::NullableIntoWasmAbi for $t $(where $($w)*)? {
14            #[inline]
15            fn null() -> Self::MaybeAbi {
16                $null
17            }
18        }
19    };
20}
21
22/// The receiving side of [`impl_nullable_into_shared_abi!`].
23macro_rules! impl_nullable_from_shared_abi {
24    (is_null = |$abi:ident| $is_null:expr; [$($g:tt)*] $t:ty $(where $($w:tt)*)?) => {
25        impl<$($g)*> $crate::convert::NullableFromWasmAbi for $t $(where $($w)*)? {
26            #[inline]
27            fn is_null($abi: &Self::MaybeAbi) -> bool {
28                $is_null
29            }
30        }
31    };
32}
33
34pub(crate) use impl_nullable_into_shared_abi;
35
36mod closures;
37mod impls;
38mod slices;
39mod traits;
40
41pub use self::impls::*;
42pub use self::slices::{VectorRefIntoWasmAbi, WasmSlice};
43pub use self::traits::*;