diff --git a/src/array_string.rs b/src/array_string.rs index 2c5f422..ee1b0aa 100644 --- a/src/array_string.rs +++ b/src/array_string.rs @@ -77,6 +77,18 @@ impl> ArrayString { #[inline] pub fn capacity(&self) -> usize { A::capacity() } + /// Return if the `ArrayString` is completely filled. + /// + /// ``` + /// use arrayvec::ArrayString; + /// + /// let mut string = ArrayString::<[_; 1]>::new(); + /// assert!(!string.is_full()); + /// string.push_str("A"); + /// assert!(string.is_full()); + /// ``` + pub fn is_full(&self) -> bool { self.len() == self.capacity() } + /// Adds the given char to the end of the string. /// /// Returns `Ok` if the push succeeds. diff --git a/src/lib.rs b/src/lib.rs index 3c9305f..f651811 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -125,6 +125,18 @@ impl ArrayVec { #[inline] pub fn capacity(&self) -> usize { A::capacity() } + /// Return if the `ArrayVec` is completely filled. + /// + /// ``` + /// use arrayvec::ArrayVec; + /// + /// let mut array = ArrayVec::<[_; 1]>::new(); + /// assert!(!array.is_full()); + /// array.push(1); + /// assert!(array.is_full()); + /// ``` + pub fn is_full(&self) -> bool { self.len() == self.capacity() } + /// Push `element` to the end of the vector. /// /// Return `None` if the push succeeds, or and return `Some(` *element* `)`