Skip to content

Commit af692e2

Browse files
committed
feat: make indexmap and indexset no-std
1 parent b56f035 commit af692e2

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@
9898
//! [`with_capacity_and_hasher`][IndexMap::with_capacity_and_hasher] instead.
9999
//! A no-std compatible hasher will be needed as well, for example
100100
//! from the crate `twox-hash`.
101-
//! - Macros [`indexmap!`] and [`indexset!`] are unavailable without `std`.
102101
103102
#![cfg_attr(docsrs, feature(doc_cfg))]
104103

src/macros.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#[cfg(feature = "std")]
2-
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
31
#[macro_export]
42
/// Create an [`IndexMap`][crate::IndexMap] from a list of key-value pairs
53
///
@@ -26,7 +24,8 @@ macro_rules! indexmap {
2624
// Note: `stringify!($key)` is just here to consume the repetition,
2725
// but we throw away that string literal during constant evaluation.
2826
const CAP: usize = <[()]>::len(&[$({ stringify!($key); }),*]);
29-
let mut map = $crate::IndexMap::with_capacity(CAP);
27+
#[allow(unused_mut)]
28+
let mut map = $crate::IndexMap::with_capacity_and_hasher(CAP, <_>::default());
3029
$(
3130
map.insert($key, $value);
3231
)*
@@ -35,8 +34,6 @@ macro_rules! indexmap {
3534
};
3635
}
3736

38-
#[cfg(feature = "std")]
39-
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
4037
#[macro_export]
4138
/// Create an [`IndexSet`][crate::IndexSet] from a list of values
4239
///
@@ -63,7 +60,8 @@ macro_rules! indexset {
6360
// Note: `stringify!($value)` is just here to consume the repetition,
6461
// but we throw away that string literal during constant evaluation.
6562
const CAP: usize = <[()]>::len(&[$({ stringify!($value); }),*]);
66-
let mut set = $crate::IndexSet::with_capacity(CAP);
63+
#[allow(unused_mut)]
64+
let mut set = $crate::IndexSet::with_capacity_and_hasher(CAP, <_>::default());
6765
$(
6866
set.insert($value);
6967
)*

0 commit comments

Comments
 (0)