maybe-rayon-0.1.1/.cargo_vcs_info.json0000644000000001360000000000100132560ustar { "git": { "sha1": "73128cfb26624d9ceef7d0796e868904841f611d" }, "path_in_vcs": "" }maybe-rayon-0.1.1/.gitignore000064400000000000000000000000231046102023000140310ustar 00000000000000/target Cargo.lock maybe-rayon-0.1.1/CHANGELOG.md000064400000000000000000000001771046102023000136640ustar 00000000000000## Version 0.1.1 - Use `Infallible` instead of `Result` - Always inline passthrough methods to guarantee zero overhead maybe-rayon-0.1.1/Cargo.toml0000644000000015630000000000100112610ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2021" name = "maybe-rayon" version = "0.1.1" description = "Either acts as rayon or creates a single-threaded facade" homepage = "https://github.com/shssoichiro/maybe-rayon" license = "MIT" repository = "https://github.com/shssoichiro/maybe-rayon" [dependencies.cfg-if] version = "1.0" [dependencies.rayon] version = "1.0" optional = true [features] default = ["threads"] threads = ["rayon"] maybe-rayon-0.1.1/Cargo.toml.orig000064400000000000000000000007611046102023000147410ustar 00000000000000[package] name = "maybe-rayon" version = "0.1.1" edition = "2021" license = "MIT" description = "Either acts as rayon or creates a single-threaded facade" homepage = "https://github.com/shssoichiro/maybe-rayon" repository = "https://github.com/shssoichiro/maybe-rayon" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] cfg-if = "1.0" rayon = { optional = true, version = "1.0" } [features] default = ["threads"] threads = ["rayon"] maybe-rayon-0.1.1/LICENSE000064400000000000000000000020561046102023000130560ustar 00000000000000MIT License Copyright (c) 2021 Joshua Holmer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. maybe-rayon-0.1.1/rustfmt.toml000064400000000000000000000002251046102023000144460ustar 00000000000000unstable_features = true imports_layout = "HorizontalVertical" imports_granularity = "Crate" group_imports = "StdExternalCrate" format_strings = truemaybe-rayon-0.1.1/src/lib.rs000064400000000000000000000072071046102023000137570ustar 00000000000000#![warn(clippy::all)] cfg_if::cfg_if! { if #[cfg(any(not(feature = "threads"), all(target_arch="wasm32", not(target_feature = "atomics"))))] { #[derive(Default)] pub struct ThreadPoolBuilder (); impl ThreadPoolBuilder { #[inline(always)] pub fn new() -> ThreadPoolBuilder { ThreadPoolBuilder() } #[inline(always)] pub fn build(self) -> Result { Ok(ThreadPool()) } #[inline(always)] pub fn num_threads(self, _num_threads: usize) -> ThreadPoolBuilder { ThreadPoolBuilder() } } #[derive(Debug)] pub struct ThreadPool (); impl ThreadPool { #[inline(always)] pub fn install(&self, op: OP) -> R where OP: FnOnce() -> R + Send, R: Send, { op() } } pub mod iter { pub trait IntoParallelIterator { type Iter: Iterator; type Item: Send; fn into_par_iter(self) -> Self::Iter; } impl IntoParallelIterator for I where I::Item : Send { type Item = I::Item; type Iter = I::IntoIter; #[inline(always)] fn into_par_iter(self) -> I::IntoIter { self.into_iter() } } pub trait IntoParallelRefMutIterator<'data> { type Iter: IntoParallelIterator; type Item: Send + 'data; fn par_iter_mut(&'data mut self) -> Self::Iter; } impl<'data, I: 'data + ?Sized> IntoParallelRefMutIterator<'data> for I where &'data mut I: IntoParallelIterator, { type Iter = <&'data mut I as IntoParallelIterator>::Iter; type Item = <&'data mut I as IntoParallelIterator>::Item; #[inline(always)] fn par_iter_mut(&'data mut self) -> Self::Iter { self.into_par_iter() } } pub trait ParallelIterator: Iterator { #[inline(always)] fn flat_map_iter(self, f: F) -> std::iter::FlatMap where Self: Sized, U: IntoIterator, F: FnMut(::Item) -> U, { self.flat_map(f) } } impl ParallelIterator for I {} } pub mod slice { pub trait ParallelSlice { fn par_chunks_exact( &self, chunk_size: usize, ) -> std::slice::ChunksExact<'_, T>; } impl ParallelSlice for [T] { #[inline(always)] fn par_chunks_exact( &self, chunk_size: usize, ) -> std::slice::ChunksExact<'_, T> { self.chunks_exact(chunk_size) } } } pub mod prelude { pub use super::iter::*; pub use super::slice::*; } #[inline(always)] pub fn join(oper_a: A, oper_b: B) -> (RA, RB) where A: FnOnce() -> RA + Send, B: FnOnce() -> RB + Send, RA: Send, RB: Send { (oper_a(), oper_b()) } use std::marker::PhantomData; pub struct Scope<'scope>{ #[allow(clippy::type_complexity)] marker: PhantomData) + Send + Sync + 'scope>>, } impl<'scope> Scope<'scope> { #[inline(always)] pub fn spawn(&self, body: BODY) where BODY: FnOnce(&Scope<'scope>) + Send + 'scope { body(self) } } #[inline(always)] pub fn scope<'scope, OP, R>(op: OP) -> R where OP: for<'s> FnOnce(&'s Scope<'scope>) -> R + 'scope + Send, R: Send, { op(&Scope { marker: PhantomData }) } } else { pub use rayon::*; } }