RefIter: add len/is_empty methods

This commit is contained in:
Alain Zscheile 2023-09-10 00:06:15 +02:00
parent 85c07c6718
commit c0514b7e4d
2 changed files with 14 additions and 2 deletions

View file

@ -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"

View file

@ -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> {