sysinfo/
utils.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3/// Converts the value into a parallel iterator if the `multithread` feature is enabled.
4/// Uses the `rayon::iter::IntoParallelIterator` trait.
5#[cfg(all(
6    feature = "multithread",
7    not(feature = "unknown-ci"),
8    not(all(target_os = "macos", feature = "apple-sandbox")),
9))]
10#[allow(dead_code)]
11pub(crate) fn into_iter<T>(val: T) -> T::Iter
12where
13    T: rayon::iter::IntoParallelIterator,
14{
15    val.into_par_iter()
16}
17
18/// Converts the value into a sequential iterator if the `multithread` feature is disabled.
19/// Uses the `std::iter::IntoIterator` trait.
20#[cfg(any(
21    not(feature = "multithread"),
22    feature = "unknown-ci",
23    all(target_os = "macos", feature = "apple-sandbox")
24))]
25#[allow(dead_code)]
26pub(crate) fn into_iter<T>(val: T) -> T::IntoIter
27where
28    T: IntoIterator,
29{
30    val.into_iter()
31}
32
33/// Converts the value into a parallel mutable iterator if the `multithread` feature is enabled.
34/// Uses the `rayon::iter::IntoParallelRefMutIterator` trait.
35#[cfg(all(
36    feature = "multithread",
37    not(feature = "unknown-ci"),
38    not(all(target_os = "macos", feature = "apple-sandbox")),
39))]
40pub(crate) fn into_iter_mut<'a, T>(
41    val: &'a mut T,
42) -> <T as rayon::iter::IntoParallelRefMutIterator<'a>>::Iter
43where
44    T: rayon::iter::IntoParallelRefMutIterator<'a> + ?Sized,
45{
46    val.par_iter_mut()
47}
48
49// In the multithreaded version of `into_iter_mut` above, the `&mut` on the argument is indicating
50// the parallel iterator is an exclusive reference. In the non-multithreaded case, the `&mut` is
51// already part of `T` and specifying it will result in the argument being `&mut &mut T`.
52
53/// Converts the value into a sequential mutable iterator if the `multithread` feature is disabled.
54/// Uses the `std::iter::IntoIterator` trait.
55#[cfg(any(
56    not(feature = "multithread"),
57    feature = "unknown-ci",
58    all(target_os = "macos", feature = "apple-sandbox")
59))]
60pub(crate) fn into_iter_mut<T>(val: T) -> T::IntoIter
61where
62    T: IntoIterator,
63{
64    val.into_iter()
65}