1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* SPDX-License-Identifier: MIT
* Copyright (c) 2023 - 2026. The DeepCausality Authors and Contributors. All Rights Reserved.
*/
//! Shared parallelism primitives for the DeepCausality workspace.
//!
//! Two items live here:
//!
//! * [`MaybeParallel`], the feature-conditional thread-safety marker that
//! the `parallel` features of `deep_causality_topology`,
//! `deep_causality_fft`, and their consumers share. Hosting it in one
//! Tier-0 crate guarantees a single definition; Cargo feature
//! unification on `deep_causality_par/parallel` keeps every crate in a
//! build agreeing on whether the bound means `Send + Sync` or nothing.
//! * [`scoped_map`], the minimal in-house fork-join surface for few,
//! long, data-independent tasks such as counterfactual branch fan-outs:
//! an order-preserving parallel map over a slice on
//! `std::thread::scope` threads under the `parallel` feature, a plain
//! inline map without it. No thread pool, no external dependency.
//!
//! # Feature levels
//!
//! `default = ["std"]`, `std = ["alloc"]`, `alloc = []`, and
//! `no-std = ["alloc"]` follow the workspace three-level convention. The
//! crate's own needs are small: `core` for the marker trait, `alloc` for
//! the [`Vec`](alloc::vec::Vec) that [`scoped_map`] returns. There is no
//! external dependency to forward a level to, so `std` and `no-std` differ
//! only in whether the crate declares `no_std`. Bare-metal builds use
//! `--no-default-features --features no-std` and get the serial inline
//! map.
//!
//! # Why `parallel = ["std"]` stays
//!
//! The parallel arm of [`scoped_map`] calls `std::thread::scope` and
//! `std::thread::available_parallelism`, and neither exists in `core` or
//! `alloc`. `parallel` therefore declares a dependency on `std`, and that
//! declaration earns its place: it is what makes a bare `--features
//! parallel` resolve to a working configuration, and what lets a
//! downstream crate forward `deep_causality_par/parallel` on its own
//! (`deep_causality_algorithms`, `deep_causality_topology`,
//! `deep_causality_cfd`, and `deep_causality_physics` all do) without also
//! having to remember `deep_causality_par/std`. Dropping it would turn
//! every one of those into a build error on the host, which is the common
//! case. `deep_causality_fft` states the same requirement the same way.
//!
//! What the declaration does **not** do is make `no-std` plus `parallel`
//! unrepresentable. Cargo features are additive and cannot express mutual
//! exclusion: `--features no-std,parallel` does not disable `parallel`, it
//! re-enables `std` underneath the `no-std` request. On a host that is
//! harmless, because the resulting `std` build is a valid one and only the
//! `no-std` request is dropped; `--all-features` relies on exactly that.
//! On a target that has no `std` to re-enable, it used to surface as
//! `can't find crate for `std`` plus a cascade of prelude errors that name
//! neither the feature that caused them nor the way out. The
//! `compile_error!` below states both instead.
// Rejects `parallel` on a target that has no `std` to fall back on, which
// is the one place where the additive `parallel = ["std"]` edge cannot
// deliver what it promises. Keyed on the target rather than on
// `feature = "no-std"` so that host builds carrying both flags — every
// `--all-features` build in CI does — stay unaffected.
compile_error!;
extern crate alloc;
pub use cratescoped_map;
pub use crateMaybeParallel;