From bbfab8c3fa308320b7f7a62e3447ec5e79441605 Mon Sep 17 00:00:00 2001 From: Akase Haruka Date: Sat, 4 Jan 2025 04:42:54 +0800 Subject: [PATCH] feat: re-export rayon traits implementations (#836) * re-export rayon traits implementations * fix * merge imports --- Cargo.toml | 1 + crates/primitives/Cargo.toml | 5 ++++- crates/primitives/src/map/mod.rs | 25 +++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 3007ea58b..28783d15a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -101,6 +101,7 @@ pretty_assertions = "1.4" proptest = "1" proptest-derive = "0.5" rand = { version = "0.8", default-features = false } +rayon = { version = "1.2", default-features = false } ruint = { version = "1.12.3", default-features = false, features = ["alloc"] } ruint-macro = { version = "1", default-features = false } winnow = { version = "0.6", default-features = false, features = ["alloc"] } diff --git a/crates/primitives/Cargo.toml b/crates/primitives/Cargo.toml index 81076830e..6707db775 100644 --- a/crates/primitives/Cargo.toml +++ b/crates/primitives/Cargo.toml @@ -64,6 +64,9 @@ getrandom = { workspace = true, optional = true } # rand rand = { workspace = true, optional = true, features = ["getrandom"] } +# rayon +rayon = { workspace = true, optional = true } + # k256 k256 = { workspace = true, optional = true, features = ["ecdsa"] } @@ -132,7 +135,7 @@ map-fxhash = ["map", "dep:rustc-hash"] getrandom = ["dep:getrandom"] k256 = ["dep:k256"] rand = ["dep:rand", "getrandom", "ruint/rand", "rustc-hash?/rand"] -rayon = ["hashbrown?/rayon", "indexmap?/rayon"] +rayon = ["dep:rayon", "hashbrown?/rayon", "indexmap?/rayon"] rlp = ["dep:alloy-rlp", "ruint/alloy-rlp"] serde = [ "dep:serde", diff --git a/crates/primitives/src/map/mod.rs b/crates/primitives/src/map/mod.rs index 4481df6f1..ed7c39a02 100644 --- a/crates/primitives/src/map/mod.rs +++ b/crates/primitives/src/map/mod.rs @@ -118,6 +118,31 @@ cfg_if! { } } +/// This module contains the rayon parallel iterator types for hash maps (HashMap). +/// You will rarely need to interact with it directly unless you have need to name one +/// of the iterator types. +#[cfg(feature = "rayon")] +pub mod rayon { + use super::*; + + cfg_if! { + if #[cfg(any(feature = "map-hashbrown", not(feature = "std")))] { + pub use hashbrown::hash_map::rayon::{ + IntoParIter as IntoIter, + ParDrain as Drain, + ParIter as Iter, + ParIterMut as IterMut, + ParKeys as Keys, + ParValues as Values, + ParValuesMut as ValuesMut + }; + use ::rayon as _; + } else { + pub use ::rayon::collections::hash_map::*; + } + } +} + #[cfg(test)] mod tests { use super::*;