Skip to content

Commit 481f930

Browse files
committed
add remaining_capacity to ArrayString
1 parent e5b3c9b commit 481f930

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/array_string.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,19 @@ impl<const CAP: usize> ArrayString<CAP>
152152
/// ```
153153
pub fn is_full(&self) -> bool { self.len() == self.capacity() }
154154

155+
/// Returns the capacity left in the `ArrayString`.
156+
///
157+
/// ```
158+
/// use arrayvec::ArrayString;
159+
///
160+
/// let mut string = ArrayString::<3>::from("abc").unwrap();
161+
/// string.pop();
162+
/// assert_eq!(string.remaining_capacity(), 1);
163+
/// ```
164+
pub const fn remaining_capacity(&self) -> usize {
165+
self.capacity() - self.len()
166+
}
167+
155168
/// Adds the given char to the end of the string.
156169
///
157170
/// ***Panics*** if the backing array is not large enough to fit the additional char.

0 commit comments

Comments
 (0)