Skip to content

Commit d62a3ca

Browse files
committed
feat: replacing the map types (alloy-rs#1365)
- replacing the HashMap and HashSet from the std::collections to the alloy-primitives along with setting up the cargo file. - setting the dependencies in the cargo files
1 parent 6ff6a9d commit d62a3ca

File tree

13 files changed

+24
-22
lines changed

13 files changed

+24
-22
lines changed

crates/contract/Cargo.toml

+1-3
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,11 @@ alloy-transport.workspace = true
2727

2828
alloy-dyn-abi = { workspace = true, features = ["std"] }
2929
alloy-json-abi.workspace = true
30-
alloy-primitives.workspace = true
3130
alloy-sol-types.workspace = true
32-
3331
futures-util.workspace = true
3432
futures.workspace = true
3533
thiserror.workspace = true
36-
34+
alloy-primitives = { features = ["map"], workspace = true }
3735
alloy-pubsub = { workspace = true, optional = true }
3836

3937
[dev-dependencies]

crates/contract/src/interface.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use crate::{ContractInstance, Error, Result};
22
use alloy_dyn_abi::{DynSolValue, FunctionExt, JsonAbiExt};
33
use alloy_json_abi::{Function, JsonAbi};
44
use alloy_primitives::{Address, Selector};
5-
use std::collections::{BTreeMap, HashMap};
6-
5+
use std::collections::{BTreeMap};
6+
use alloy_primitives::map::{HashMap};
77
/// A smart contract interface.
88
#[derive(Clone, Debug)]
99
pub struct Interface {

crates/json-rpc/src/common.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ use std::fmt::Display;
1818
/// This type implements [`Hash`] so that it can be used as a key in a
1919
/// [`HashMap`] or an item in a [`HashSet`].
2020
///
21-
/// [`BTreeMap`]: std::collections::BTreeMap
22-
/// [`BTreeSet`]: std::collections::BTreeSet
23-
/// [`HashMap`]: std::collections::HashMap
24-
/// [`HashSet`]: std::collections::HashSet
21+
/// [`BTreeMap`]: alloy_primitives::map::BTreeMap
22+
/// [`BTreeSet`]: alloy_primitives::map::BTreeSet
23+
/// [`HashMap`]: alloy_primitives::map::HashMap
24+
/// [`HashSet`]: alloy_primitives::map::HashSet
2525
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
2626
pub enum Id {
2727
/// A number.

crates/rpc-types-debug/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ rustdoc-args = ["--cfg", "docsrs"]
1919
workspace = true
2020

2121
[dependencies]
22-
alloy-primitives = { workspace = true, features = ["serde", "std"] }
22+
alloy-primitives = { workspace = true, features = ["serde", "std", "map"] }
2323

2424
serde.workspace = true

crates/rpc-types-debug/src/debug.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
33
use alloy_primitives::{Bytes, B256};
44
use serde::{Deserialize, Serialize};
5-
use std::collections::HashMap;
6-
5+
//use std::collections::HashMap;
6+
use alloy_primitives::map::HashMap;
77
/// Represents the execution witness of a block. Contains an optional map of state preimages.
88
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
99
pub struct ExecutionWitness {
@@ -22,3 +22,4 @@ pub struct ExecutionWitness {
2222
#[serde(default)]
2323
pub keys: Option<HashMap<B256, Bytes>>,
2424
}
25+

crates/rpc-types-eth/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ alloy-eips.workspace = true
2323
alloy-consensus.workspace = true
2424
alloy-network-primitives.workspace = true
2525
alloy-rlp = { workspace = true, features = ["arrayvec", "derive"] }
26-
alloy-primitives = { workspace = true, features = ["rlp"] }
26+
alloy-primitives = { workspace = true, features = ["rlp", "map"] }
2727

2828
itertools.workspace = true
2929
derive_more = { workspace = true, features = ["display"] }

crates/rpc-types-eth/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extern crate alloc;
1515
pub mod collections {
1616
cfg_if::cfg_if! {
1717
if #[cfg(feature = "std")] {
18-
pub use std::collections::{hash_set, HashMap, HashSet};
18+
pub use alloy_primitives::map::{hash_set, HashMap, HashSet};
1919
use hashbrown as _;
2020
} else {
2121
pub use hashbrown::{hash_set, HashMap, HashSet};

crates/rpc-types-trace/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ rustdoc-args = ["--cfg", "docsrs"]
1919
workspace = true
2020

2121
[dependencies]
22-
alloy-primitives = { workspace = true, features = ["rlp", "serde"] }
22+
alloy-primitives = { workspace = true, features = ["rlp", "serde", "map"] }
2323
alloy-rpc-types-eth = { workspace = true, features = ["std", "serde"] }
2424
alloy-serde.workspace = true
2525

crates/rpc-types-trace/src/filter.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ use crate::parity::{
55
};
66
use alloy_primitives::Address;
77
use serde::{Deserialize, Serialize};
8-
use std::collections::HashSet;
9-
8+
use alloy_primitives::map::HashSet;
109
/// Trace filter.
1110
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
1211
#[serde(deny_unknown_fields)]

crates/rpc-types-trace/src/geth/mux.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::geth::{GethDebugBuiltInTracerType, GethDebugTracerConfig, GethTrace};
44
use serde::{Deserialize, Serialize};
5-
use std::collections::HashMap;
5+
use alloy_primitives::map::HashMap;
66

77
/// A `muxTracer` config that contains the configuration for running multiple tracers in one go.
88
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]

crates/rpc-types-trace/src/tracerequest.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use alloy_rpc_types_eth::{
55
request::TransactionRequest, state::StateOverride, BlockId, BlockOverrides,
66
};
77
use serde::{Deserialize, Serialize};
8-
use std::collections::HashSet;
8+
9+
use alloy_primitives::map::HashSet;
910

1011
/// Container type for `trace_call` arguments
1112
#[derive(Debug, Default, Serialize, Deserialize)]

crates/rpc-types/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ alloy-rpc-types-mev = { workspace = true, optional = true }
3030
alloy-rpc-types-trace = { workspace = true, optional = true }
3131
alloy-rpc-types-txpool = { workspace = true, optional = true }
3232
serde = { workspace = true, features = ["derive", "std"] }
33+
alloy-primitives = { version = "0.8.5", features = ["map"] }
3334

3435
[dev-dependencies]
3536
serde_json.workspace = true

crates/rpc-types/src/rpc.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Types for the `rpc` API.
22
use serde::{Deserialize, Serialize};
3-
use std::collections::HashMap;
4-
3+
use alloy_primitives::map::HashMap;
54
/// Represents the `rpc_modules` response, which returns the
65
/// list of all available modules on that transport and their version
76
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
@@ -28,13 +27,16 @@ mod tests {
2827
#[test]
2928
fn test_parse_module_versions_roundtrip() {
3029
let s = r#"{"txpool":"1.0","trace":"1.0","eth":"1.0","web3":"1.0","net":"1.0"}"#;
31-
let module_map = HashMap::from([
30+
let mut module_map: HashMap<String, String> = HashMap::default(); // Change to FxHashMap
31+
32+
module_map.extend([
3233
("txpool".to_owned(), "1.0".to_owned()),
3334
("trace".to_owned(), "1.0".to_owned()),
3435
("eth".to_owned(), "1.0".to_owned()),
3536
("web3".to_owned(), "1.0".to_owned()),
3637
("net".to_owned(), "1.0".to_owned()),
3738
]);
39+
3840
let m = RpcModules::new(module_map);
3941
let de_serialized: RpcModules = serde_json::from_str(s).unwrap();
4042
assert_eq!(de_serialized, m);

0 commit comments

Comments
 (0)