crcbl_hal/threading.rs
1//! Thread-safety marker for HAL traits.
2//!
3//! `CommandEncoder`, `Device`, and `Instance` require `Send + Sync` on native
4//! platforms so the job system can move them across threads. On `wasm32`, wgpu's
5//! web types are `!Send` (they use `Rc` internally), and the browser is
6//! single-threaded anyway — so the bound is a no-op.
7//!
8//! [`HalThreadSafe`] captures this conditionally: it requires `Send + Sync` on
9//! native and is implemented for **everything** on wasm.
10
11/// Marker: implementations of HAL traits must satisfy this.
12///
13/// On native: `Send + Sync`. On wasm32: automatically satisfied.
14#[cfg(not(target_arch = "wasm32"))]
15pub trait HalThreadSafe: Send + Sync {}
16
17#[cfg(not(target_arch = "wasm32"))]
18impl<T: Send + Sync> HalThreadSafe for T {}
19
20#[cfg(target_arch = "wasm32")]
21pub trait HalThreadSafe {}
22
23#[cfg(target_arch = "wasm32")]
24impl<T> HalThreadSafe for T {}