Add is_full predicate methods

This commit is contained in:
Jake Goulding
2016-05-28 10:00:38 -04:00
parent a41ecc0a29
commit b0bf84b201
2 changed files with 24 additions and 0 deletions
+12
View File
@@ -77,6 +77,18 @@ impl<A: Array<Item=u8>> ArrayString<A> {
#[inline] #[inline]
pub fn capacity(&self) -> usize { A::capacity() } 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. /// Adds the given char to the end of the string.
/// ///
/// Returns `Ok` if the push succeeds. /// Returns `Ok` if the push succeeds.
+12
View File
@@ -125,6 +125,18 @@ impl<A: Array> ArrayVec<A> {
#[inline] #[inline]
pub fn capacity(&self) -> usize { A::capacity() } 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. /// Push `element` to the end of the vector.
/// ///
/// Return `None` if the push succeeds, or and return `Some(` *element* `)` /// Return `None` if the push succeeds, or and return `Some(` *element* `)`