@@ -92,11 +92,7 @@ impl<T, S, const N: usize> IndexSet<T, BuildHasherDefault<S>, N> {
92
92
}
93
93
}
94
94
95
- impl < T , S , const N : usize > IndexSet < T , S , N >
96
- where
97
- T : Eq + Hash ,
98
- S : BuildHasher ,
99
- {
95
+ impl < T , S , const N : usize > IndexSet < T , S , N > {
100
96
/// Returns the number of elements the set can hold
101
97
///
102
98
/// # Examples
@@ -147,6 +143,60 @@ where
147
143
self . map . last ( ) . map ( |( k, _v) | k)
148
144
}
149
145
146
+ /// Returns the number of elements in the set.
147
+ ///
148
+ /// # Examples
149
+ ///
150
+ /// ```
151
+ /// use heapless::FnvIndexSet;
152
+ ///
153
+ /// let mut v: FnvIndexSet<_, 16> = FnvIndexSet::new();
154
+ /// assert_eq!(v.len(), 0);
155
+ /// v.insert(1).unwrap();
156
+ /// assert_eq!(v.len(), 1);
157
+ /// ```
158
+ pub fn len ( & self ) -> usize {
159
+ self . map . len ( )
160
+ }
161
+
162
+ /// Returns `true` if the set contains no elements.
163
+ ///
164
+ /// # Examples
165
+ ///
166
+ /// ```
167
+ /// use heapless::FnvIndexSet;
168
+ ///
169
+ /// let mut v: FnvIndexSet<_, 16> = FnvIndexSet::new();
170
+ /// assert!(v.is_empty());
171
+ /// v.insert(1).unwrap();
172
+ /// assert!(!v.is_empty());
173
+ /// ```
174
+ pub fn is_empty ( & self ) -> bool {
175
+ self . map . is_empty ( )
176
+ }
177
+
178
+ /// Clears the set, removing all values.
179
+ ///
180
+ /// # Examples
181
+ ///
182
+ /// ```
183
+ /// use heapless::FnvIndexSet;
184
+ ///
185
+ /// let mut v: FnvIndexSet<_, 16> = FnvIndexSet::new();
186
+ /// v.insert(1).unwrap();
187
+ /// v.clear();
188
+ /// assert!(v.is_empty());
189
+ /// ```
190
+ pub fn clear ( & mut self ) {
191
+ self . map . clear ( )
192
+ }
193
+ }
194
+
195
+ impl < T , S , const N : usize > IndexSet < T , S , N >
196
+ where
197
+ T : Eq + Hash ,
198
+ S : BuildHasher ,
199
+ {
150
200
/// Visits the values representing the difference, i.e. the values that are in `self` but not in
151
201
/// `other`.
152
202
///
@@ -277,54 +327,6 @@ where
277
327
self . iter ( ) . chain ( other. difference ( self ) )
278
328
}
279
329
280
- /// Returns the number of elements in the set.
281
- ///
282
- /// # Examples
283
- ///
284
- /// ```
285
- /// use heapless::FnvIndexSet;
286
- ///
287
- /// let mut v: FnvIndexSet<_, 16> = FnvIndexSet::new();
288
- /// assert_eq!(v.len(), 0);
289
- /// v.insert(1).unwrap();
290
- /// assert_eq!(v.len(), 1);
291
- /// ```
292
- pub fn len ( & self ) -> usize {
293
- self . map . len ( )
294
- }
295
-
296
- /// Returns `true` if the set contains no elements.
297
- ///
298
- /// # Examples
299
- ///
300
- /// ```
301
- /// use heapless::FnvIndexSet;
302
- ///
303
- /// let mut v: FnvIndexSet<_, 16> = FnvIndexSet::new();
304
- /// assert!(v.is_empty());
305
- /// v.insert(1).unwrap();
306
- /// assert!(!v.is_empty());
307
- /// ```
308
- pub fn is_empty ( & self ) -> bool {
309
- self . map . is_empty ( )
310
- }
311
-
312
- /// Clears the set, removing all values.
313
- ///
314
- /// # Examples
315
- ///
316
- /// ```
317
- /// use heapless::FnvIndexSet;
318
- ///
319
- /// let mut v: FnvIndexSet<_, 16> = FnvIndexSet::new();
320
- /// v.insert(1).unwrap();
321
- /// v.clear();
322
- /// assert!(v.is_empty());
323
- /// ```
324
- pub fn clear ( & mut self ) {
325
- self . map . clear ( )
326
- }
327
-
328
330
/// Returns `true` if the set contains a value.
329
331
///
330
332
/// The value may be any borrowed form of the set's value type, but `Hash` and `Eq` on the
@@ -473,7 +475,7 @@ where
473
475
474
476
impl < T , S , const N : usize > Clone for IndexSet < T , S , N >
475
477
where
476
- T : Eq + Hash + Clone ,
478
+ T : Clone ,
477
479
S : Clone ,
478
480
{
479
481
fn clone ( & self ) -> Self {
@@ -485,8 +487,7 @@ where
485
487
486
488
impl < T , S , const N : usize > fmt:: Debug for IndexSet < T , S , N >
487
489
where
488
- T : Eq + Hash + fmt:: Debug ,
489
- S : BuildHasher ,
490
+ T : fmt:: Debug ,
490
491
{
491
492
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
492
493
f. debug_set ( ) . entries ( self . iter ( ) ) . finish ( )
@@ -495,8 +496,7 @@ where
495
496
496
497
impl < T , S , const N : usize > Default for IndexSet < T , S , N >
497
498
where
498
- T : Eq + Hash ,
499
- S : BuildHasher + Default ,
499
+ S : Default ,
500
500
{
501
501
fn default ( ) -> Self {
502
502
IndexSet {
0 commit comments