From 481f93084eecebda0445cb7f81b40b9789dd1559 Mon Sep 17 00:00:00 2001 From: "Brandon H. Gomes" Date: Sun, 1 Aug 2021 13:53:21 -0400 Subject: [PATCH] add remaining_capacity to ArrayString --- src/array_string.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/array_string.rs b/src/array_string.rs index a044cb5..257c26a 100644 --- a/src/array_string.rs +++ b/src/array_string.rs @@ -152,6 +152,19 @@ impl ArrayString /// ``` 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.