
# Objective The clippy lint `type_complexity` is known not to play well with bevy. It frequently triggers when writing complex queries, and taking the lint's advice of using a type alias almost always just obfuscates the code with no benefit. Because of this, this lint is currently ignored in CI, but unfortunately it still shows up when viewing bevy code in an IDE. As someone who's made a fair amount of pull requests to this repo, I will say that this issue has been a consistent thorn in my side. Since bevy code is filled with spurious, ignorable warnings, it can be very difficult to spot the *real* warnings that must be fixed -- most of the time I just ignore all warnings, only to later find out that one of them was real after I'm done when CI runs. ## Solution Suppress this lint in all bevy crates. This was previously attempted in #7050, but the review process ended up making it more complicated than it needs to be and landed on a subpar solution. The discussion in https://github.com/rust-lang/rust-clippy/pull/10571 explores some better long-term solutions to this problem. Since there is no timeline on when these solutions may land, we should resolve this issue in the meantime by locally suppressing these lints. ### Unresolved issues Currently, these lints are not suppressed in our examples, since that would require suppressing the lint in every single source file. They are still ignored in CI.
57 lines
1.5 KiB
Rust
57 lines
1.5 KiB
Rust
#![warn(missing_docs)]
|
|
#![allow(clippy::type_complexity)]
|
|
#![doc = include_str!("../README.md")]
|
|
|
|
mod slice;
|
|
pub use slice::{ParallelSlice, ParallelSliceMut};
|
|
|
|
mod task;
|
|
pub use task::Task;
|
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
|
mod task_pool;
|
|
#[cfg(not(target_arch = "wasm32"))]
|
|
pub use task_pool::{Scope, TaskPool, TaskPoolBuilder};
|
|
|
|
#[cfg(target_arch = "wasm32")]
|
|
mod single_threaded_task_pool;
|
|
#[cfg(target_arch = "wasm32")]
|
|
pub use single_threaded_task_pool::{Scope, TaskPool, TaskPoolBuilder, ThreadExecutor};
|
|
|
|
mod usages;
|
|
#[cfg(not(target_arch = "wasm32"))]
|
|
pub use usages::tick_global_task_pools_on_main_thread;
|
|
pub use usages::{AsyncComputeTaskPool, ComputeTaskPool, IoTaskPool};
|
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
|
mod thread_executor;
|
|
#[cfg(not(target_arch = "wasm32"))]
|
|
pub use thread_executor::{ThreadExecutor, ThreadExecutorTicker};
|
|
|
|
mod iter;
|
|
pub use iter::ParallelIterator;
|
|
|
|
#[allow(missing_docs)]
|
|
pub mod prelude {
|
|
#[doc(hidden)]
|
|
pub use crate::{
|
|
iter::ParallelIterator,
|
|
slice::{ParallelSlice, ParallelSliceMut},
|
|
usages::{AsyncComputeTaskPool, ComputeTaskPool, IoTaskPool},
|
|
};
|
|
}
|
|
|
|
use std::num::NonZeroUsize;
|
|
|
|
/// Gets the logical CPU core count available to the current process.
|
|
///
|
|
/// This is identical to [`std::thread::available_parallelism`], except
|
|
/// it will return a default value of 1 if it internally errors out.
|
|
///
|
|
/// This will always return at least 1.
|
|
pub fn available_parallelism() -> usize {
|
|
std::thread::available_parallelism()
|
|
.map(NonZeroUsize::get)
|
|
.unwrap_or(1)
|
|
}
|