@@ -92,11 +92,7 @@ impl<T, S, const N: usize> IndexSet<T, BuildHasherDefault<S>, N> {
9292 }
9393}
9494
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 > {
10096 /// Returns the number of elements the set can hold
10197 ///
10298 /// # Examples
@@ -147,6 +143,60 @@ where
147143 self . map . last ( ) . map ( |( k, _v) | k)
148144 }
149145
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+ {
150200 /// Visits the values representing the difference, i.e. the values that are in `self` but not in
151201 /// `other`.
152202 ///
@@ -277,54 +327,6 @@ where
277327 self . iter ( ) . chain ( other. difference ( self ) )
278328 }
279329
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-
328330 /// Returns `true` if the set contains a value.
329331 ///
330332 /// The value may be any borrowed form of the set's value type, but `Hash` and `Eq` on the
@@ -473,7 +475,7 @@ where
473475
474476impl < T , S , const N : usize > Clone for IndexSet < T , S , N >
475477where
476- T : Eq + Hash + Clone ,
478+ T : Clone ,
477479 S : Clone ,
478480{
479481 fn clone ( & self ) -> Self {
@@ -485,8 +487,7 @@ where
485487
486488impl < T , S , const N : usize > fmt:: Debug for IndexSet < T , S , N >
487489where
488- T : Eq + Hash + fmt:: Debug ,
489- S : BuildHasher ,
490+ T : fmt:: Debug ,
490491{
491492 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
492493 f. debug_set ( ) . entries ( self . iter ( ) ) . finish ( )
@@ -495,8 +496,7 @@ where
495496
496497impl < T , S , const N : usize > Default for IndexSet < T , S , N >
497498where
498- T : Eq + Hash ,
499- S : BuildHasher + Default ,
499+ S : Default ,
500500{
501501 fn default ( ) -> Self {
502502 IndexSet {
0 commit comments