add remaining_capacity to ArrayString

This commit is contained in:
Brandon H. Gomes
2021-08-01 13:53:21 -04:00
parent e5b3c9bc6c
commit 481f93084e
+13
View File
@@ -152,6 +152,19 @@ impl<const CAP: usize> ArrayString<CAP>
/// ```
pub fn is_full(&self) -> bool { self.len() == self.capacity() }
/// Returns the capacity left in the `ArrayString`.
///
/// ```
/// use arrayvec::ArrayString;
///
/// let mut string = ArrayString::<3>::from("abc").unwrap();
/// string.pop();
/// assert_eq!(string.remaining_capacity(), 1);
/// ```
pub const fn remaining_capacity(&self) -> usize {
self.capacity() - self.len()
}
/// Adds the given char to the end of the string.
///
/// ***Panics*** if the backing array is not large enough to fit the additional char.