Coverage Report

Created: 2023-04-25 07:07

/rust/registry/src/index.crates.io-6f17d22bba15001f/rayon-1.5.2/src/lib.rs
Line
Count
Source (jump to first uncovered line)
1
#![doc(html_root_url = "https://docs.rs/rayon/1.5")]
2
#![deny(missing_debug_implementations)]
3
#![deny(missing_docs)]
4
#![deny(unreachable_pub)]
5
#![warn(rust_2018_idioms)]
6
7
//! Data-parallelism library that makes it easy to convert sequential
8
//! computations into parallel
9
//!
10
//! Rayon is lightweight and convenient for introducing parallelism into existing
11
//! code. It guarantees data-race free executions and takes advantage of
12
//! parallelism when sensible, based on work-load at runtime.
13
//!
14
//! # How to use Rayon
15
//!
16
//! There are two ways to use Rayon:
17
//!
18
//! - **High-level parallel constructs** are the simplest way to use Rayon and also
19
//!   typically the most efficient.
20
//!   - [Parallel iterators][iter module] make it easy to convert a sequential iterator to
21
//!     execute in parallel.
22
//!     - The [`ParallelIterator`] trait defines general methods for all parallel iterators.
23
//!     - The [`IndexedParallelIterator`] trait adds methods for iterators that support random
24
//!       access.
25
//!   - The [`par_sort`] method sorts `&mut [T]` slices (or vectors) in parallel.
26
//!   - [`par_extend`] can be used to efficiently grow collections with items produced
27
//!     by a parallel iterator.
28
//! - **Custom tasks** let you divide your work into parallel tasks yourself.
29
//!   - [`join`] is used to subdivide a task into two pieces.
30
//!   - [`scope`] creates a scope within which you can create any number of parallel tasks.
31
//!   - [`ThreadPoolBuilder`] can be used to create your own thread pools or customize
32
//!     the global one.
33
//!
34
//! [iter module]: iter/index.html
35
//! [`join`]: fn.join.html
36
//! [`scope`]: fn.scope.html
37
//! [`par_sort`]: slice/trait.ParallelSliceMut.html#method.par_sort
38
//! [`par_extend`]: iter/trait.ParallelExtend.html#tymethod.par_extend
39
//! [`ThreadPoolBuilder`]: struct.ThreadPoolBuilder.html
40
//!
41
//! # Basic usage and the Rayon prelude
42
//!
43
//! First, you will need to add `rayon` to your `Cargo.toml`.
44
//!
45
//! Next, to use parallel iterators or the other high-level methods,
46
//! you need to import several traits. Those traits are bundled into
47
//! the module [`rayon::prelude`]. It is recommended that you import
48
//! all of these traits at once by adding `use rayon::prelude::*` at
49
//! the top of each module that uses Rayon methods.
50
//!
51
//! These traits give you access to the `par_iter` method which provides
52
//! parallel implementations of many iterative functions such as [`map`],
53
//! [`for_each`], [`filter`], [`fold`], and [more].
54
//!
55
//! [`rayon::prelude`]: prelude/index.html
56
//! [`map`]: iter/trait.ParallelIterator.html#method.map
57
//! [`for_each`]: iter/trait.ParallelIterator.html#method.for_each
58
//! [`filter`]: iter/trait.ParallelIterator.html#method.filter
59
//! [`fold`]: iter/trait.ParallelIterator.html#method.fold
60
//! [more]: iter/trait.ParallelIterator.html#provided-methods
61
//! [`ParallelIterator`]: iter/trait.ParallelIterator.html
62
//! [`IndexedParallelIterator`]: iter/trait.IndexedParallelIterator.html
63
//!
64
//! # Crate Layout
65
//!
66
//! Rayon extends many of the types found in the standard library with
67
//! parallel iterator implementations. The modules in the `rayon`
68
//! crate mirror [`std`] itself: so, e.g., the `option` module in
69
//! Rayon contains parallel iterators for the `Option` type, which is
70
//! found in [the `option` module of `std`]. Similarly, the
71
//! `collections` module in Rayon offers parallel iterator types for
72
//! [the `collections` from `std`]. You will rarely need to access
73
//! these submodules unless you need to name iterator types
74
//! explicitly.
75
//!
76
//! [the `option` module of `std`]: https://doc.rust-lang.org/std/option/index.html
77
//! [the `collections` from `std`]: https://doc.rust-lang.org/std/collections/index.html
78
//! [`std`]: https://doc.rust-lang.org/std/
79
//!
80
//! # Other questions?
81
//!
82
//! See [the Rayon FAQ][faq].
83
//!
84
//! [faq]: https://github.com/rayon-rs/rayon/blob/master/FAQ.md
85
86
#[macro_use]
87
mod delegate;
88
89
#[macro_use]
90
mod private;
91
92
mod split_producer;
93
94
pub mod array;
95
pub mod collections;
96
pub mod iter;
97
pub mod option;
98
pub mod prelude;
99
pub mod range;
100
pub mod range_inclusive;
101
pub mod result;
102
pub mod slice;
103
pub mod str;
104
pub mod string;
105
pub mod vec;
106
107
mod math;
108
mod par_either;
109
110
mod compile_fail;
111
112
pub use rayon_core::FnContext;
113
pub use rayon_core::ThreadBuilder;
114
pub use rayon_core::ThreadPool;
115
pub use rayon_core::ThreadPoolBuildError;
116
pub use rayon_core::ThreadPoolBuilder;
117
pub use rayon_core::{current_num_threads, current_thread_index, max_num_threads};
118
pub use rayon_core::{in_place_scope, scope, Scope};
119
pub use rayon_core::{in_place_scope_fifo, scope_fifo, ScopeFifo};
120
pub use rayon_core::{join, join_context};
121
pub use rayon_core::{spawn, spawn_fifo};
122
123
/// We need to transmit raw pointers across threads. It is possible to do this
124
/// without any unsafe code by converting pointers to usize or to AtomicPtr<T>
125
/// then back to a raw pointer for use. We prefer this approach because code
126
/// that uses this type is more explicit.
127
///
128
/// Unsafe code is still required to dereference the pointer, so this type is
129
/// not unsound on its own, although it does partly lift the unconditional
130
/// !Send and !Sync on raw pointers. As always, dereference with care.
131
struct SendPtr<T>(*mut T);
132
133
// SAFETY: !Send for raw pointers is not for safety, just as a lint
134
unsafe impl<T: Send> Send for SendPtr<T> {}
135
136
// SAFETY: !Sync for raw pointers is not for safety, just as a lint
137
unsafe impl<T: Send> Sync for SendPtr<T> {}
138
139
// Implement Clone without the T: Clone bound from the derive
140
impl<T> Clone for SendPtr<T> {
141
0
    fn clone(&self) -> Self {
142
0
        Self(self.0)
143
0
    }
144
}
145
146
// Implement Copy without the T: Copy bound from the derive
147
impl<T> Copy for SendPtr<T> {}