Skip to content

Commit e66f3b2

Browse files
committed
Highlight feature-gated items in documentation
1 parent 1f308f1 commit e66f3b2

File tree

9 files changed

+29
-39
lines changed

9 files changed

+29
-39
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ no-dev-version = true
5353
tag-name = "{{version}}"
5454

5555
[package.metadata.docs.rs]
56-
features = ["arbitrary", "quickcheck", "serde", "rayon"]
56+
all-features = true
57+
rustdoc-args = ["--cfg", "docsrs"]
5758

5859
[workspace]
5960
members = ["test-nostd", "test-serde"]

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@
7676
//!
7777
//! [def]: map/struct.IndexMap.html#impl-Default
7878
79+
#![cfg_attr(docsrs, feature(doc_cfg))]
80+
7981
extern crate alloc;
8082

8183
#[cfg(feature = "std")]
@@ -92,6 +94,7 @@ mod mutable_keys;
9294
#[cfg(feature = "serde")]
9395
mod serde;
9496
#[cfg(feature = "serde")]
97+
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
9598
pub mod serde_seq;
9699
mod util;
97100

@@ -245,4 +248,5 @@ impl core::fmt::Display for TryReserveError {
245248
}
246249

247250
#[cfg(feature = "std")]
251+
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
248252
impl std::error::Error for TryReserveError {}

src/macros.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#[cfg(feature = "std")]
2+
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
23
#[macro_export]
34
/// Create an `IndexMap` from a list of key-value pairs
45
///
@@ -35,6 +36,7 @@ macro_rules! indexmap {
3536
}
3637

3738
#[cfg(feature = "std")]
39+
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
3840
#[macro_export]
3941
/// Create an `IndexSet` from a list of values
4042
///

src/map.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ where
148148
}
149149

150150
#[cfg(feature = "std")]
151+
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
151152
impl<K, V> IndexMap<K, V> {
152153
/// Create a new map. (Does not allocate.)
153154
#[inline]
@@ -1112,6 +1113,8 @@ where
11121113
}
11131114

11141115
#[cfg(feature = "std")]
1116+
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
1117+
11151118
impl<K, V, const N: usize> From<[(K, V); N]> for IndexMap<K, V, RandomState>
11161119
where
11171120
K: Hash + Eq,

src/rayon/map.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
//!
33
//! You will rarely need to interact with this module directly unless you need to name one of the
44
//! iterator types.
5-
//!
6-
//! Requires crate feature `"rayon"`
5+
6+
#![cfg_attr(docsrs, doc(cfg(feature = "rayon")))]
77

88
use super::collect;
99
use rayon::iter::plumbing::{Consumer, ProducerCallback, UnindexedConsumer};
@@ -21,7 +21,6 @@ use crate::Bucket;
2121
use crate::Entries;
2222
use crate::IndexMap;
2323

24-
/// Requires crate feature `"rayon"`.
2524
impl<K, V, S> IntoParallelIterator for IndexMap<K, V, S>
2625
where
2726
K: Send,
@@ -37,7 +36,6 @@ where
3736
}
3837
}
3938

40-
/// Requires crate feature `"rayon"`.
4139
impl<K, V> IntoParallelIterator for Box<Slice<K, V>>
4240
where
4341
K: Send,
@@ -81,7 +79,6 @@ impl<K: Send, V: Send> IndexedParallelIterator for IntoParIter<K, V> {
8179
indexed_parallel_iterator_methods!(Bucket::key_value);
8280
}
8381

84-
/// Requires crate feature `"rayon"`.
8582
impl<'a, K, V, S> IntoParallelIterator for &'a IndexMap<K, V, S>
8683
where
8784
K: Sync,
@@ -97,7 +94,6 @@ where
9794
}
9895
}
9996

100-
/// Requires crate feature `"rayon"`.
10197
impl<'a, K, V> IntoParallelIterator for &'a Slice<K, V>
10298
where
10399
K: Sync,
@@ -147,7 +143,6 @@ impl<K: Sync, V: Sync> IndexedParallelIterator for ParIter<'_, K, V> {
147143
indexed_parallel_iterator_methods!(Bucket::refs);
148144
}
149145

150-
/// Requires crate feature `"rayon"`.
151146
impl<'a, K, V, S> IntoParallelIterator for &'a mut IndexMap<K, V, S>
152147
where
153148
K: Sync + Send,
@@ -163,7 +158,6 @@ where
163158
}
164159
}
165160

166-
/// Requires crate feature `"rayon"`.
167161
impl<'a, K, V> IntoParallelIterator for &'a mut Slice<K, V>
168162
where
169163
K: Sync + Send,
@@ -207,7 +201,6 @@ impl<K: Sync + Send, V: Send> IndexedParallelIterator for ParIterMut<'_, K, V> {
207201
indexed_parallel_iterator_methods!(Bucket::ref_mut);
208202
}
209203

210-
/// Requires crate feature `"rayon"`.
211204
impl<'a, K, V, S> ParallelDrainRange<usize> for &'a mut IndexMap<K, V, S>
212205
where
213206
K: Send,
@@ -395,7 +388,6 @@ impl<K: Sync, V: Sync> IndexedParallelIterator for ParValues<'_, K, V> {
395388
indexed_parallel_iterator_methods!(Bucket::value_ref);
396389
}
397390

398-
/// Requires crate feature `"rayon"`.
399391
impl<K, V, S> IndexMap<K, V, S>
400392
where
401393
K: Send,
@@ -412,7 +404,6 @@ where
412404
}
413405
}
414406

415-
/// Requires crate feature `"rayon"`.
416407
impl<K, V> Slice<K, V>
417408
where
418409
K: Send,
@@ -546,7 +537,6 @@ impl<K: Send, V: Send> IndexedParallelIterator for ParValuesMut<'_, K, V> {
546537
indexed_parallel_iterator_methods!(Bucket::value_mut);
547538
}
548539

549-
/// Requires crate feature `"rayon"`.
550540
impl<K, V, S> FromParallelIterator<(K, V)> for IndexMap<K, V, S>
551541
where
552542
K: Eq + Hash + Send,
@@ -567,7 +557,6 @@ where
567557
}
568558
}
569559

570-
/// Requires crate feature `"rayon"`.
571560
impl<K, V, S> ParallelExtend<(K, V)> for IndexMap<K, V, S>
572561
where
573562
K: Eq + Hash + Send,
@@ -584,7 +573,6 @@ where
584573
}
585574
}
586575

587-
/// Requires crate feature `"rayon"`.
588576
impl<'a, K: 'a, V: 'a, S> ParallelExtend<(&'a K, &'a V)> for IndexMap<K, V, S>
589577
where
590578
K: Copy + Eq + Hash + Send + Sync,

src/rayon/set.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
//!
33
//! You will rarely need to interact with this module directly unless you need to name one of the
44
//! iterator types.
5-
//!
6-
//! Requires crate feature `"rayon"`.
5+
6+
#![cfg_attr(docsrs, doc(cfg(feature = "rayon")))]
77

88
use super::collect;
99
use rayon::iter::plumbing::{Consumer, ProducerCallback, UnindexedConsumer};
@@ -22,7 +22,7 @@ use crate::IndexSet;
2222

2323
type Bucket<T> = crate::Bucket<T, ()>;
2424

25-
/// Requires crate feature `"rayon"`.
25+
#[cfg_attr(docsrs, doc(cfg(feature = "rayon")))]
2626
impl<T, S> IntoParallelIterator for IndexSet<T, S>
2727
where
2828
T: Send,
@@ -37,7 +37,7 @@ where
3737
}
3838
}
3939

40-
/// Requires crate feature `"rayon"`.
40+
#[cfg_attr(docsrs, doc(cfg(feature = "rayon")))]
4141
impl<T> IntoParallelIterator for Box<Slice<T>>
4242
where
4343
T: Send,
@@ -80,7 +80,7 @@ impl<T: Send> IndexedParallelIterator for IntoParIter<T> {
8080
indexed_parallel_iterator_methods!(Bucket::key);
8181
}
8282

83-
/// Requires crate feature `"rayon"`.
83+
#[cfg_attr(docsrs, doc(cfg(feature = "rayon")))]
8484
impl<'a, T, S> IntoParallelIterator for &'a IndexSet<T, S>
8585
where
8686
T: Sync,
@@ -95,7 +95,7 @@ where
9595
}
9696
}
9797

98-
/// Requires crate feature `"rayon"`.
98+
#[cfg_attr(docsrs, doc(cfg(feature = "rayon")))]
9999
impl<'a, T> IntoParallelIterator for &'a Slice<T>
100100
where
101101
T: Sync,
@@ -144,7 +144,7 @@ impl<T: Sync> IndexedParallelIterator for ParIter<'_, T> {
144144
indexed_parallel_iterator_methods!(Bucket::key_ref);
145145
}
146146

147-
/// Requires crate feature `"rayon"`.
147+
#[cfg_attr(docsrs, doc(cfg(feature = "rayon")))]
148148
impl<'a, T, S> ParallelDrainRange<usize> for &'a mut IndexSet<T, S>
149149
where
150150
T: Send,
@@ -585,7 +585,7 @@ where
585585
}
586586
}
587587

588-
/// Requires crate feature `"rayon"`.
588+
#[cfg_attr(docsrs, doc(cfg(feature = "rayon")))]
589589
impl<T, S> FromParallelIterator<T> for IndexSet<T, S>
590590
where
591591
T: Eq + Hash + Send,
@@ -605,7 +605,7 @@ where
605605
}
606606
}
607607

608-
/// Requires crate feature `"rayon"`.
608+
#[cfg_attr(docsrs, doc(cfg(feature = "rayon")))]
609609
impl<T, S> ParallelExtend<T> for IndexSet<T, S>
610610
where
611611
T: Eq + Hash + Send,
@@ -621,7 +621,7 @@ where
621621
}
622622
}
623623

624-
/// Requires crate feature `"rayon"`.
624+
#[cfg_attr(docsrs, doc(cfg(feature = "rayon")))]
625625
impl<'a, T: 'a, S> ParallelExtend<&'a T> for IndexSet<T, S>
626626
where
627627
T: Copy + Eq + Hash + Send + Sync,

src/serde.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(docsrs, doc(cfg(feature = "serde")))]
2+
13
use serde::de::value::{MapDeserializer, SeqDeserializer};
24
use serde::de::{
35
Deserialize, Deserializer, Error, IntoDeserializer, MapAccess, SeqAccess, Visitor,
@@ -10,7 +12,6 @@ use core::marker::PhantomData;
1012

1113
use crate::IndexMap;
1214

13-
/// Requires crate feature `"serde"`
1415
impl<K, V, S> Serialize for IndexMap<K, V, S>
1516
where
1617
K: Serialize + Hash + Eq,
@@ -54,7 +55,6 @@ where
5455
}
5556
}
5657

57-
/// Requires crate feature `"serde"`
5858
impl<'de, K, V, S> Deserialize<'de> for IndexMap<K, V, S>
5959
where
6060
K: Deserialize<'de> + Eq + Hash,
@@ -85,7 +85,6 @@ where
8585

8686
use crate::IndexSet;
8787

88-
/// Requires crate feature `"serde"`
8988
impl<T, S> Serialize for IndexSet<T, S>
9089
where
9190
T: Serialize + Hash + Eq,
@@ -127,7 +126,6 @@ where
127126
}
128127
}
129128

130-
/// Requires crate feature `"serde"`
131129
impl<'de, T, S> Deserialize<'de> for IndexSet<T, S>
132130
where
133131
T: Deserialize<'de> + Eq + Hash,

src/serde_seq.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
//! // ...
1818
//! }
1919
//! ```
20-
//!
21-
//! Requires crate feature `"serde"`
20+
21+
#![cfg_attr(docsrs, doc(cfg(feature = "serde")))]
2222

2323
use serde::de::{Deserialize, Deserializer, SeqAccess, Visitor};
2424
use serde::ser::{Serialize, Serializer};
@@ -35,8 +35,6 @@ use crate::IndexMap;
3535
///
3636
/// This behaves like [`crate::serde_seq`] for `IndexMap`, serializing a sequence
3737
/// of `(key, value)` pairs, rather than as a map that might not preserve order.
38-
///
39-
/// Requires crate feature `"serde"`
4038
impl<K, V> Serialize for MapSlice<K, V>
4139
where
4240
K: Serialize,
@@ -51,8 +49,6 @@ where
5149
}
5250

5351
/// Serializes a `set::Slice` as an ordered sequence.
54-
///
55-
/// Requires crate feature `"serde"`
5652
impl<T> Serialize for SetSlice<T>
5753
where
5854
T: Serialize,
@@ -79,8 +75,6 @@ where
7975
/// // ...
8076
/// }
8177
/// ```
82-
///
83-
/// Requires crate feature `"serde"`
8478
pub fn serialize<K, V, S, T>(map: &IndexMap<K, V, S>, serializer: T) -> Result<T::Ok, T::Error>
8579
where
8680
K: Serialize + Hash + Eq,
@@ -135,8 +129,6 @@ where
135129
/// // ...
136130
/// }
137131
/// ```
138-
///
139-
/// Requires crate feature `"serde"`
140132
pub fn deserialize<'de, D, K, V, S>(deserializer: D) -> Result<IndexMap<K, V, S>, D::Error>
141133
where
142134
D: Deserializer<'de>,

src/set.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ where
135135
}
136136

137137
#[cfg(feature = "std")]
138+
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
138139
impl<T> IndexSet<T> {
139140
/// Create a new set. (Does not allocate.)
140141
pub fn new() -> Self {
@@ -841,6 +842,7 @@ where
841842
}
842843

843844
#[cfg(feature = "std")]
845+
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
844846
impl<T, const N: usize> From<[T; N]> for IndexSet<T, RandomState>
845847
where
846848
T: Eq + Hash,

0 commit comments

Comments
 (0)