Skip to content

Conversation

@tcharding
Copy link
Member

@tcharding tcharding commented May 10, 2022

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.

Implement is_empty on the TokenIter struct.

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.
Copy link
Member

@sanket1729 sanket1729 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK cb51a5b

@sanket1729 sanket1729 merged commit 9dc1d47 into rust-bitcoin:master May 10, 2022
Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

post-merge ACK cb51a5b

@tcharding tcharding deleted the 05-10-is-empty branch May 10, 2022 21:22
heap-coder added a commit to heap-coder/rust-miniscript that referenced this pull request Sep 27, 2025
…nIter`

cb51a5b3dbf51dce4474a73d54f35878f551c754 Implement is_empty on TokenIter (Tobin C. Harding)

Pull request description:

  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.

  Implement `is_empty` on the `TokenIter` struct.

Top commit has no ACKs.

Tree-SHA512: b0b832ac9457b9eef725b4589198212d90ea66faa4788792551da31a7601b928edbd7658f33862ed8210478cc4512af4ebb35be1cddf9d66ac67f6222f282a3e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants