xwt_core/utils/maybe.rs
1//! Marker traits for enabling [`Send`] and [`Sync`] requirements based on the
2//! target family.
3//!
4//! Normally we want to require real [`core::marker::Send`] and
5//! [`core::marker::Sync`] for most of the types, however, the Web API bindings
6//! can not support those, and in the Web setting, the spawning of async tasks
7//! does not currently require those either.
8//! So we turn off the [`core::marker::Send`] and [`core::marker::Sync`]
9//! requirements for the Web targets using these [`Send`] and [`Sync`] traits.
10
11/// Maybe a [`core::marker::Send`].
12///
13/// For this target - a real [`core::marker::Send`] requirement.
14#[cfg(not(target_family = "wasm"))]
15pub trait Send: core::marker::Send {}
16
17#[cfg(not(target_family = "wasm"))]
18impl<T> self::Send for T where T: core::marker::Send {}
19
20/// Maybe a [`core::marker::Send`].
21///
22/// For this target - NO [`core::marker::Send`] requirement.
23#[cfg(target_family = "wasm")]
24pub trait Send {}
25
26#[cfg(target_family = "wasm")]
27impl<T> self::Send for T {}
28
29/// Maybe a [`core::marker::Sync`].
30///
31/// For this target - a real [`core::marker::Sync`] requirement.
32#[cfg(not(target_family = "wasm"))]
33pub trait Sync: core::marker::Sync {}
34
35#[cfg(not(target_family = "wasm"))]
36impl<T> self::Sync for T where T: core::marker::Sync {}
37
38/// Maybe a [`core::marker::Sync`].
39///
40/// For this target - NO [`core::marker::Sync`] requirement.
41#[cfg(target_family = "wasm")]
42pub trait Sync {}
43
44#[cfg(target_family = "wasm")]
45impl<T> self::Sync for T {}