From cb51a5b3dbf51dce4474a73d54f35878f551c754 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Tue, 10 May 2022 15:01:08 +1000 Subject: [PATCH] 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. --- src/miniscript/lex.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/miniscript/lex.rs b/src/miniscript/lex.rs index ae8cbffe3..feeb00505 100644 --- a/src/miniscript/lex.rs +++ b/src/miniscript/lex.rs @@ -102,6 +102,11 @@ impl<'s> TokenIter<'s> { pub fn len(&self) -> usize { self.0.len() } + + /// Returns true if iterator is empty. + pub fn is_empty(&self) -> bool { + self.0.is_empty() + } } impl<'s> Iterator for TokenIter<'s> {