Skip to content

Commit badc118

Browse files
authored
Merge pull request #143 from nicbn/is_empty
Add is_empty method for ArrayVec and ArrayString
2 parents 481c8ab + 633c863 commit badc118

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/array_string.rs

+4
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

+12
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,18 @@ impl<A: Array> ArrayVec<A> {
124124
#[inline]
125125
pub fn len(&self) -> usize { self.len.to_usize() }
126126

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

0 commit comments

Comments
 (0)