Skip to content

Commit cb51a5b

Browse files
committed
Implement is_empty on TokenIter
Clippy emits: ``` warning: struct `TokenIter` has a public `len` method, but no `is_empty` method --> src/miniscript/lex.rs:102:5 | 102 | pub fn len(&self) -> usize { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(clippy::len_without_is_empty)]` on by default = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#len_without_is_empty ``` Iterators typically do not implement `is_empty` because there is often no way for an iterator to know if there are more items without calling `next`, however we use a `Vec` under the hood so `is_empty` is cheap.
1 parent c0076e6 commit cb51a5b

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/miniscript/lex.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ impl<'s> TokenIter<'s> {
102102
pub fn len(&self) -> usize {
103103
self.0.len()
104104
}
105+
106+
/// Returns true if iterator is empty.
107+
pub fn is_empty(&self) -> bool {
108+
self.0.is_empty()
109+
}
105110
}
106111

107112
impl<'s> Iterator for TokenIter<'s> {

0 commit comments

Comments
 (0)