FEAT: Add ArrayVec.capacity_left

This commit is contained in:
Thomas de Zeeuw
2018-07-17 14:46:53 +02:00
parent d84cb377a9
commit d11c853346
2 changed files with 27 additions and 0 deletions
+13
View File
@@ -172,6 +172,19 @@ impl<A: Array> ArrayVec<A> {
/// ```
pub fn is_full(&self) -> bool { self.len() == self.capacity() }
/// Returns the capacity left in the `ArrayVec`.
///
/// ```
/// use arrayvec::ArrayVec;
///
/// let mut array = ArrayVec::from([1, 2, 3]);
/// array.pop();
/// assert_eq!(array.capacity_left(), 1);
/// ```
pub fn capacity_left(&self) -> usize {
self.capacity() - self.len()
}
/// Push `element` to the end of the vector.
///
/// ***Panics*** if the vector is already full.