Skip to content

Commit

Permalink
add remaining_capacity to ArrayString
Browse files Browse the repository at this point in the history
  • Loading branch information
bhgomes committed Aug 1, 2021
1 parent e5b3c9b commit 481f930
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/array_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 481f930

Please sign in to comment.