mirror of
				https://github.com/rust-embedded/heapless.git
				synced 2025-11-04 06:56:48 +00:00 
			
		
		
		
	relax trait requirements on IndexSet
Signed-off-by: Jean-Pierre De Jesus DIAZ <me@jeandudey.tech>
This commit is contained in:
		
							parent
							
								
									c9cc18ada7
								
							
						
					
					
						commit
						d5802449e5
					
				@ -22,7 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
 | 
				
			|||||||
- renamed `pool::singleton::arc::Pool` to `ArcPool` and moved it into the `pool::arc` module
 | 
					- renamed `pool::singleton::arc::Pool` to `ArcPool` and moved it into the `pool::arc` module
 | 
				
			||||||
- [breaking-change] changed the target support of memory pool API to only support 32-bit x86 and a
 | 
					- [breaking-change] changed the target support of memory pool API to only support 32-bit x86 and a
 | 
				
			||||||
  subset of ARM targets. See the module level documentation of the `pool` module for details
 | 
					  subset of ARM targets. See the module level documentation of the `pool` module for details
 | 
				
			||||||
- relax trait requirements on `IndexMap`.
 | 
					- relax trait requirements on `IndexMap` and `IndexSet`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- [breaking-change] this crate now depends on `atomic-polyfill` v1.0.1, meaning that targets that
 | 
					- [breaking-change] this crate now depends on `atomic-polyfill` v1.0.1, meaning that targets that
 | 
				
			||||||
  require a polyfill need a `critical-section` **v1.x.x** implementation.
 | 
					  require a polyfill need a `critical-section` **v1.x.x** implementation.
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										116
									
								
								src/indexset.rs
									
									
									
									
									
								
							
							
						
						
									
										116
									
								
								src/indexset.rs
									
									
									
									
									
								
							@ -92,11 +92,7 @@ impl<T, S, const N: usize> IndexSet<T, BuildHasherDefault<S>, N> {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl<T, S, const N: usize> IndexSet<T, S, N>
 | 
					impl<T, S, const N: usize> IndexSet<T, S, N> {
 | 
				
			||||||
where
 | 
					 | 
				
			||||||
    T: Eq + Hash,
 | 
					 | 
				
			||||||
    S: BuildHasher,
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    /// Returns the number of elements the set can hold
 | 
					    /// Returns the number of elements the set can hold
 | 
				
			||||||
    ///
 | 
					    ///
 | 
				
			||||||
    /// # Examples
 | 
					    /// # Examples
 | 
				
			||||||
@ -147,6 +143,60 @@ where
 | 
				
			|||||||
        self.map.last().map(|(k, _v)| k)
 | 
					        self.map.last().map(|(k, _v)| k)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// Returns the number of elements in the set.
 | 
				
			||||||
 | 
					    ///
 | 
				
			||||||
 | 
					    /// # Examples
 | 
				
			||||||
 | 
					    ///
 | 
				
			||||||
 | 
					    /// ```
 | 
				
			||||||
 | 
					    /// use heapless::FnvIndexSet;
 | 
				
			||||||
 | 
					    ///
 | 
				
			||||||
 | 
					    /// let mut v: FnvIndexSet<_, 16> = FnvIndexSet::new();
 | 
				
			||||||
 | 
					    /// assert_eq!(v.len(), 0);
 | 
				
			||||||
 | 
					    /// v.insert(1).unwrap();
 | 
				
			||||||
 | 
					    /// assert_eq!(v.len(), 1);
 | 
				
			||||||
 | 
					    /// ```
 | 
				
			||||||
 | 
					    pub fn len(&self) -> usize {
 | 
				
			||||||
 | 
					        self.map.len()
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// Returns `true` if the set contains no elements.
 | 
				
			||||||
 | 
					    ///
 | 
				
			||||||
 | 
					    /// # Examples
 | 
				
			||||||
 | 
					    ///
 | 
				
			||||||
 | 
					    /// ```
 | 
				
			||||||
 | 
					    /// use heapless::FnvIndexSet;
 | 
				
			||||||
 | 
					    ///
 | 
				
			||||||
 | 
					    /// let mut v: FnvIndexSet<_, 16> = FnvIndexSet::new();
 | 
				
			||||||
 | 
					    /// assert!(v.is_empty());
 | 
				
			||||||
 | 
					    /// v.insert(1).unwrap();
 | 
				
			||||||
 | 
					    /// assert!(!v.is_empty());
 | 
				
			||||||
 | 
					    /// ```
 | 
				
			||||||
 | 
					    pub fn is_empty(&self) -> bool {
 | 
				
			||||||
 | 
					        self.map.is_empty()
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// Clears the set, removing all values.
 | 
				
			||||||
 | 
					    ///
 | 
				
			||||||
 | 
					    /// # Examples
 | 
				
			||||||
 | 
					    ///
 | 
				
			||||||
 | 
					    /// ```
 | 
				
			||||||
 | 
					    /// use heapless::FnvIndexSet;
 | 
				
			||||||
 | 
					    ///
 | 
				
			||||||
 | 
					    /// let mut v: FnvIndexSet<_, 16> = FnvIndexSet::new();
 | 
				
			||||||
 | 
					    /// v.insert(1).unwrap();
 | 
				
			||||||
 | 
					    /// v.clear();
 | 
				
			||||||
 | 
					    /// assert!(v.is_empty());
 | 
				
			||||||
 | 
					    /// ```
 | 
				
			||||||
 | 
					    pub fn clear(&mut self) {
 | 
				
			||||||
 | 
					        self.map.clear()
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl<T, S, const N: usize> IndexSet<T, S, N>
 | 
				
			||||||
 | 
					where
 | 
				
			||||||
 | 
					    T: Eq + Hash,
 | 
				
			||||||
 | 
					    S: BuildHasher,
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    /// Visits the values representing the difference, i.e. the values that are in `self` but not in
 | 
					    /// Visits the values representing the difference, i.e. the values that are in `self` but not in
 | 
				
			||||||
    /// `other`.
 | 
					    /// `other`.
 | 
				
			||||||
    ///
 | 
					    ///
 | 
				
			||||||
@ -277,54 +327,6 @@ where
 | 
				
			|||||||
        self.iter().chain(other.difference(self))
 | 
					        self.iter().chain(other.difference(self))
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// Returns the number of elements in the set.
 | 
					 | 
				
			||||||
    ///
 | 
					 | 
				
			||||||
    /// # Examples
 | 
					 | 
				
			||||||
    ///
 | 
					 | 
				
			||||||
    /// ```
 | 
					 | 
				
			||||||
    /// use heapless::FnvIndexSet;
 | 
					 | 
				
			||||||
    ///
 | 
					 | 
				
			||||||
    /// let mut v: FnvIndexSet<_, 16> = FnvIndexSet::new();
 | 
					 | 
				
			||||||
    /// assert_eq!(v.len(), 0);
 | 
					 | 
				
			||||||
    /// v.insert(1).unwrap();
 | 
					 | 
				
			||||||
    /// assert_eq!(v.len(), 1);
 | 
					 | 
				
			||||||
    /// ```
 | 
					 | 
				
			||||||
    pub fn len(&self) -> usize {
 | 
					 | 
				
			||||||
        self.map.len()
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /// Returns `true` if the set contains no elements.
 | 
					 | 
				
			||||||
    ///
 | 
					 | 
				
			||||||
    /// # Examples
 | 
					 | 
				
			||||||
    ///
 | 
					 | 
				
			||||||
    /// ```
 | 
					 | 
				
			||||||
    /// use heapless::FnvIndexSet;
 | 
					 | 
				
			||||||
    ///
 | 
					 | 
				
			||||||
    /// let mut v: FnvIndexSet<_, 16> = FnvIndexSet::new();
 | 
					 | 
				
			||||||
    /// assert!(v.is_empty());
 | 
					 | 
				
			||||||
    /// v.insert(1).unwrap();
 | 
					 | 
				
			||||||
    /// assert!(!v.is_empty());
 | 
					 | 
				
			||||||
    /// ```
 | 
					 | 
				
			||||||
    pub fn is_empty(&self) -> bool {
 | 
					 | 
				
			||||||
        self.map.is_empty()
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /// Clears the set, removing all values.
 | 
					 | 
				
			||||||
    ///
 | 
					 | 
				
			||||||
    /// # Examples
 | 
					 | 
				
			||||||
    ///
 | 
					 | 
				
			||||||
    /// ```
 | 
					 | 
				
			||||||
    /// use heapless::FnvIndexSet;
 | 
					 | 
				
			||||||
    ///
 | 
					 | 
				
			||||||
    /// let mut v: FnvIndexSet<_, 16> = FnvIndexSet::new();
 | 
					 | 
				
			||||||
    /// v.insert(1).unwrap();
 | 
					 | 
				
			||||||
    /// v.clear();
 | 
					 | 
				
			||||||
    /// assert!(v.is_empty());
 | 
					 | 
				
			||||||
    /// ```
 | 
					 | 
				
			||||||
    pub fn clear(&mut self) {
 | 
					 | 
				
			||||||
        self.map.clear()
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /// Returns `true` if the set contains a value.
 | 
					    /// Returns `true` if the set contains a value.
 | 
				
			||||||
    ///
 | 
					    ///
 | 
				
			||||||
    /// The value may be any borrowed form of the set's value type, but `Hash` and `Eq` on the
 | 
					    /// The value may be any borrowed form of the set's value type, but `Hash` and `Eq` on the
 | 
				
			||||||
@ -473,7 +475,7 @@ where
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
impl<T, S, const N: usize> Clone for IndexSet<T, S, N>
 | 
					impl<T, S, const N: usize> Clone for IndexSet<T, S, N>
 | 
				
			||||||
where
 | 
					where
 | 
				
			||||||
    T: Eq + Hash + Clone,
 | 
					    T: Clone,
 | 
				
			||||||
    S: Clone,
 | 
					    S: Clone,
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    fn clone(&self) -> Self {
 | 
					    fn clone(&self) -> Self {
 | 
				
			||||||
@ -485,8 +487,7 @@ where
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
impl<T, S, const N: usize> fmt::Debug for IndexSet<T, S, N>
 | 
					impl<T, S, const N: usize> fmt::Debug for IndexSet<T, S, N>
 | 
				
			||||||
where
 | 
					where
 | 
				
			||||||
    T: Eq + Hash + fmt::Debug,
 | 
					    T: fmt::Debug,
 | 
				
			||||||
    S: BuildHasher,
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 | 
					    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 | 
				
			||||||
        f.debug_set().entries(self.iter()).finish()
 | 
					        f.debug_set().entries(self.iter()).finish()
 | 
				
			||||||
@ -495,8 +496,7 @@ where
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
impl<T, S, const N: usize> Default for IndexSet<T, S, N>
 | 
					impl<T, S, const N: usize> Default for IndexSet<T, S, N>
 | 
				
			||||||
where
 | 
					where
 | 
				
			||||||
    T: Eq + Hash,
 | 
					    S: Default,
 | 
				
			||||||
    S: BuildHasher + Default,
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    fn default() -> Self {
 | 
					    fn default() -> Self {
 | 
				
			||||||
        IndexSet {
 | 
					        IndexSet {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user