bevy/crates/bevy_tasks/src
Zachary Harrold 0403948aa2
Remove Implicit std Prelude from no_std Crates (#17086)
# Background

In `no_std` compatible crates, there is often an `std` feature which
will allow access to the standard library. Currently, with the `std`
feature _enabled_, the
[`std::prelude`](https://doc.rust-lang.org/std/prelude/index.html) is
implicitly imported in all modules. With the feature _disabled_, instead
the [`core::prelude`](https://doc.rust-lang.org/core/prelude/index.html)
is implicitly imported. This creates a subtle and pervasive issue where
`alloc` items _may_ be implicitly included (if `std` is enabled), or
must be explicitly included (if `std` is not enabled).

# Objective

- Make the implicit imports for `no_std` crates consistent regardless of
what features are/not enabled.

## Solution

- Replace the `cfg_attr` "double negative" `no_std` attribute with
conditional compilation to _include_ `std` as an external crate.
```rust
// Before
#![cfg_attr(not(feature = "std"), no_std)]

// After
#![no_std]

#[cfg(feature = "std")]
extern crate std;
```
- Fix imports that are currently broken but are only now visible with
the above fix.

## Testing

- CI

## Notes

I had previously used the "double negative" version of `no_std` based on
general consensus that it was "cleaner" within the Rust embedded
community. However, this implicit prelude issue likely was considered
when forming this consensus. I believe the reason why is the items most
affected by this issue are provided by the `alloc` crate, which is
rarely used within embedded but extensively used within Bevy.
2025-01-03 01:58:43 +00:00
..
iter Add no_std support to bevy_tasks (#15464) 2024-12-06 02:14:54 +00:00
executor.rs bevy_tasks: Apply #[deny(clippy::allow_attributes, clippy::allow_attributes_without_reason)] (#17089) 2025-01-02 22:42:25 +00:00
futures.rs Move futures.rs, ConditionalSend and BoxedFuture types to bevy_tasks (#16951) 2024-12-29 19:29:53 +00:00
lib.rs Remove Implicit std Prelude from no_std Crates (#17086) 2025-01-03 01:58:43 +00:00
single_threaded_task_pool.rs Remove Implicit std Prelude from no_std Crates (#17086) 2025-01-03 01:58:43 +00:00
slice.rs Remove Implicit std Prelude from no_std Crates (#17086) 2025-01-03 01:58:43 +00:00
task_pool.rs Remove Implicit std Prelude from no_std Crates (#17086) 2025-01-03 01:58:43 +00:00
task.rs Fix no_std CI Warnings and WASM Compatibility (#17049) 2024-12-30 23:01:27 +00:00
thread_executor.rs Fix no_std CI Warnings and WASM Compatibility (#17049) 2024-12-30 23:01:27 +00:00
usages.rs Remove bevy_core (#16897) 2024-12-19 18:36:51 +00:00
wasm_task.rs Fix no_std CI Warnings and WASM Compatibility (#17049) 2024-12-30 23:01:27 +00:00