Skip to content

Commit 266d74c

Browse files
authored
Merge pull request #9 from cuviper/release-0.5.6
Release 0.5.6
2 parents 055e45e + 5a091d8 commit 266d74c

File tree

4 files changed

+85
-4
lines changed

4 files changed

+85
-4
lines changed

Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "ordermap"
33
edition = "2021"
4-
version = "0.5.5"
4+
version = "0.5.6"
55
documentation = "https://docs.rs/ordermap/"
66
repository = "https://github.com/indexmap-rs/ordermap"
77
license = "Apache-2.0 OR MIT"
@@ -14,7 +14,7 @@ rust-version = "1.63"
1414
bench = false
1515

1616
[dependencies]
17-
indexmap = { version = "2.7.1", default-features = false }
17+
indexmap = { version = "2.8.0", default-features = false }
1818

1919
arbitrary = { version = "1.0", optional = true, default-features = false }
2020
quickcheck = { version = "1.0", optional = true, default-features = false }
@@ -24,7 +24,7 @@ rayon = { version = "1.9", optional = true }
2424

2525
[dev-dependencies]
2626
itertools = "0.14"
27-
rand = {version = "0.8", features = ["small_rng"] }
27+
rand = {version = "0.9", features = ["small_rng"] }
2828
quickcheck = { version = "1.0", default-features = false }
2929
fnv = "1.0"
3030
lazy_static = "1.3"

RELEASES.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Releases
22

3+
## 0.5.6 (2025-03-10)
4+
5+
- Added `ordermap_with_default!` and `orderset_with_default!` to be used with
6+
alternative hashers, especially when using the crate without `std`.
7+
- Updated the `indexmap` dependency to version 2.8.0.
8+
39
## 0.5.5 (2025-01-19)
410

511
- Added `#[track_caller]` to functions that may panic.

src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@
9292
//! [`with_capacity_and_hasher`][OrderMap::with_capacity_and_hasher] instead.
9393
//! A no-std compatible hasher will be needed as well, for example
9494
//! from the crate `twox-hash`.
95-
//! - Macros [`ordermap!`] and [`orderset!`] are unavailable without `std`.
95+
//! - Macros [`ordermap!`] and [`orderset!`] are unavailable without `std`. Use
96+
//! the macros [`ordermap_with_default!`] and [`orderset_with_default!`] instead.
9697
9798
#![cfg_attr(docsrs, feature(doc_cfg))]
9899

src/macros.rs

+74
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,40 @@
1+
/// Create an [`OrderMap`][crate::OrderMap] from a list of key-value pairs
2+
/// and a `BuildHasherDefault`-wrapped custom hasher.
3+
///
4+
/// ## Example
5+
///
6+
/// ```
7+
/// use ordermap::ordermap_with_default;
8+
/// use fnv::FnvHasher;
9+
///
10+
/// let map = ordermap_with_default!{
11+
/// FnvHasher;
12+
/// "a" => 1,
13+
/// "b" => 2,
14+
/// };
15+
/// assert_eq!(map["a"], 1);
16+
/// assert_eq!(map["b"], 2);
17+
/// assert_eq!(map.get("c"), None);
18+
///
19+
/// // "a" is the first key
20+
/// assert_eq!(map.keys().next(), Some(&"a"));
21+
/// ```
22+
#[macro_export]
23+
macro_rules! ordermap_with_default {
24+
($H:ty; $($key:expr => $value:expr,)+) => { $crate::ordermap_with_default!($H; $($key => $value),+) };
25+
($H:ty; $($key:expr => $value:expr),*) => {{
26+
let builder = ::core::hash::BuildHasherDefault::<$H>::default();
27+
const CAP: usize = <[()]>::len(&[$({ stringify!($key); }),*]);
28+
#[allow(unused_mut)]
29+
// Specify your custom `H` (must implement Default + Hasher) as the hasher:
30+
let mut map = $crate::OrderMap::with_capacity_and_hasher(CAP, builder);
31+
$(
32+
map.insert($key, $value);
33+
)*
34+
map
35+
}};
36+
}
37+
138
#[cfg(feature = "std")]
239
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
340
#[macro_export]
@@ -35,6 +72,43 @@ macro_rules! ordermap {
3572
};
3673
}
3774

75+
/// Create an [`OrderSet`][crate::OrderSet] from a list of values
76+
/// and a `BuildHasherDefault`-wrapped custom hasher.
77+
///
78+
/// ## Example
79+
///
80+
/// ```
81+
/// use ordermap::orderset_with_default;
82+
/// use fnv::FnvHasher;
83+
///
84+
/// let set = orderset_with_default!{
85+
/// FnvHasher;
86+
/// "a",
87+
/// "b",
88+
/// };
89+
/// assert!(set.contains("a"));
90+
/// assert!(set.contains("b"));
91+
/// assert!(!set.contains("c"));
92+
///
93+
/// // "a" is the first value
94+
/// assert_eq!(set.iter().next(), Some(&"a"));
95+
/// ```
96+
#[macro_export]
97+
macro_rules! orderset_with_default {
98+
($H:ty; $($value:expr,)+) => { $crate::orderset_with_default!($H; $($value),+) };
99+
($H:ty; $($value:expr),*) => {{
100+
let builder = ::core::hash::BuildHasherDefault::<$H>::default();
101+
const CAP: usize = <[()]>::len(&[$({ stringify!($value); }),*]);
102+
#[allow(unused_mut)]
103+
// Specify your custom `H` (must implement Default + Hash) as the hasher:
104+
let mut set = $crate::OrderSet::with_capacity_and_hasher(CAP, builder);
105+
$(
106+
set.insert($value);
107+
)*
108+
set
109+
}};
110+
}
111+
38112
#[cfg(feature = "std")]
39113
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
40114
#[macro_export]

0 commit comments

Comments
 (0)