deep_causality_par/traits/maybe_parallel.rs
1/*
2 * SPDX-License-Identifier: MIT
3 * Copyright (c) 2023 - 2026. The DeepCausality Authors and Contributors. All Rights Reserved.
4 */
5
6//! Feature-conditional thread-safety alias.
7//!
8//! Parallel code paths (the per-cell DEC operator loops in
9//! `deep_causality_topology`, the batched 1-D transforms in
10//! `deep_causality_fft`) fan out over Rayon when their `parallel`
11//! features are enabled, which requires the scalar to cross threads.
12//! This alias trait expresses that requirement without forcing
13//! `Send + Sync` on serial builds:
14//!
15//! - **`parallel` on**: `MaybeParallel ≡ Send + Sync` (blanket-implemented
16//! for every such type — all workspace scalars qualify).
17//! - **`parallel` off**: `MaybeParallel` is empty and blanket-implemented
18//! for every type, so the bound is vacuous and the public API is
19//! unchanged.
20//!
21//! Bound additions of the form `R: … + MaybeParallel` on impl blocks are
22//! therefore invisible to serial consumers and exactly the Rayon
23//! requirement for parallel ones. Downstream crates forward their own
24//! `parallel` feature to `deep_causality_par/parallel`, so feature
25//! unification keeps the single definition consistent across a build.
26
27/// Thread-safety requirement of feature-gated parallel loops; vacuous
28/// without the `parallel` feature. See the module doc.
29#[cfg(feature = "parallel")]
30pub trait MaybeParallel: Send + Sync {}
31
32#[cfg(feature = "parallel")]
33impl<T: Send + Sync + ?Sized> MaybeParallel for T {}
34
35/// Thread-safety requirement of feature-gated parallel loops; vacuous
36/// without the `parallel` feature. See the module doc.
37#[cfg(not(feature = "parallel"))]
38pub trait MaybeParallel {}
39
40#[cfg(not(feature = "parallel"))]
41impl<T: ?Sized> MaybeParallel for T {}