Skip to content

Commit 633c863

Browse files
committed
Add is_empty method for ArrayVec and ArrayString
1 parent fc6664c commit 633c863

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/array_string.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ impl<A> ArrayString<A>
7171
#[inline]
7272
pub fn len(&self) -> usize { self.len.to_usize() }
7373

74+
/// Returns whether the string is empty.
75+
#[inline]
76+
pub fn is_empty(&self) -> bool { self.len() == 0 }
77+
7478
/// Create a new `ArrayString` from a `str`.
7579
///
7680
/// Capacity is inferred from the type parameter.

src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,18 @@ impl<A: Array> ArrayVec<A> {
126126
#[inline]
127127
pub fn len(&self) -> usize { self.len.to_usize() }
128128

129+
/// Returns whether the `ArrayVec` is empty.
130+
///
131+
/// ```
132+
/// use arrayvec::ArrayVec;
133+
///
134+
/// let mut array = ArrayVec::from([1]);
135+
/// array.pop();
136+
/// assert_eq!(array.is_empty(), true);
137+
/// ```
138+
#[inline]
139+
pub fn is_empty(&self) -> bool { self.len() == 0 }
140+
129141
/// Return the capacity of the `ArrayVec`.
130142
///
131143
/// ```

0 commit comments

Comments
 (0)