Skip to main content

huff_neo_utils/
wasm.rs

1cfg_if::cfg_if! {
2    if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] {
3        /// Implements a shim for the `into_par_iter` which wasm32 does not support
4        pub trait IntoParallelIterator {
5            /// The type of item yielded by the iterator
6            type Item;
7            /// The type of the iterator
8            type IntoIter: Iterator<Item = Self::Item>;
9
10            /// Returns a non-parallel iterator
11            fn into_par_iter(self) -> Self::IntoIter;
12        }
13
14        impl<T> IntoParallelIterator for Vec<T> {
15            type Item = T;
16            type IntoIter = std::vec::IntoIter<T>;
17
18            fn into_par_iter(self) -> Self::IntoIter {
19                self.into_iter()
20            }
21        }
22
23        impl<'data, T: Sync + 'data> IntoParallelIterator for &'data Vec<T> {
24            type Item = &'data T;
25            type IntoIter = std::slice::Iter<'data, T>;
26
27            fn into_par_iter(self) -> Self::IntoIter {
28                <&[T]>::into_iter(self)
29            }
30        }
31    }
32}