embassy-sync: Add capacity and free_capacity functions to Channel
This commit is contained in:
		
							parent
							
								
									fa94b5cec0
								
							
						
					
					
						commit
						3d9b502c7a
					
				| @ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |||||||
| 
 | 
 | ||||||
| ## Unreleased | ## Unreleased | ||||||
| 
 | 
 | ||||||
| - Add `len`, `is_empty` and `is_full` functions to `Channel`. | - Add `capacity`, `free_capacity`, `len`, `is_empty` and `is_full` functions to `Channel`. | ||||||
| 
 | 
 | ||||||
| ## 0.5.0 - 2023-12-04 | ## 0.5.0 - 2023-12-04 | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -620,6 +620,18 @@ where | |||||||
|         self.lock(|c| c.try_receive()) |         self.lock(|c| c.try_receive()) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /// Returns the maximum number of elements the channel can hold.
 | ||||||
|  |     pub const fn capacity(&self) -> usize { | ||||||
|  |         N | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /// Returns the free capacity of the channel.
 | ||||||
|  |     ///
 | ||||||
|  |     /// This is equivalent to `capacity() - len()`
 | ||||||
|  |     pub fn free_capacity(&self) -> usize { | ||||||
|  |         N - self.len() | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     /// Returns the number of elements currently in the channel.
 |     /// Returns the number of elements currently in the channel.
 | ||||||
|     pub fn len(&self) -> usize { |     pub fn len(&self) -> usize { | ||||||
|         self.lock(|c| c.len()) |         self.lock(|c| c.len()) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user