RefIter: add len/is_empty methods
This commit is contained in:
parent
85c07c6718
commit
c0514b7e4d
2 changed files with 14 additions and 2 deletions
|
@ -2,7 +2,7 @@
|
|||
name = "varstack"
|
||||
description = "A call-stack based singly-linked list"
|
||||
repository = "https://git.exozy.me/fogti/varstack.git"
|
||||
version = "0.2.3"
|
||||
version = "0.2.4"
|
||||
edition = "2021"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
||||
|
|
14
src/ref.rs
14
src/ref.rs
|
@ -82,7 +82,7 @@ impl<'s, V> RefStack<'s, V> {
|
|||
false
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[inline(always)]
|
||||
pub fn len(&self) -> usize {
|
||||
self.iter().count()
|
||||
}
|
||||
|
@ -105,6 +105,18 @@ impl<'s, V> IntoIterator for &'s RefStack<'s, V> {
|
|||
|
||||
pub struct RefIter<'s, V>(pub Option<&'s RefStack<'s, V>>);
|
||||
|
||||
impl<'s, V> RefIter<'s, V> {
|
||||
#[inline(always)]
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.0.is_none()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn len(&self) -> usize {
|
||||
self.count()
|
||||
}
|
||||
}
|
||||
|
||||
impl<V> marker::Copy for RefIter<'_, V> {}
|
||||
|
||||
impl<V> clone::Clone for RefIter<'_, V> {
|
||||
|
|
Loading…
Reference in a new issue