itertools icon indicating copy to clipboard operation
itertools copied to clipboard

ExactlyOneError doesn't always implement Debug

Open TomFryersMidsummer opened this issue 4 months ago • 0 comments

This means you sometimes can't use Result::expect on the result of exactly_one.

use itertools::Itertools;
fn foo(cows: impl Iterator<Item = i32>) -> i32 {
    cows.exactly_one().expect("there should only be one cow")
}
error[E0277]: `impl Iterator<Item = i32>` doesn't implement `Debug`
    --> ...:3:24
     |
   2 |     cows.exactly_one().expect("there should only be one cow")
     |                        ^^^^^^ the trait `Debug` is not implemented for `impl Iterator<Item = i32>`
     |
     = note: required for `ExactlyOneError<impl Iterator<Item = i32>>` to implement `Debug`
...

You can work-around it by doing .collect_array().expect(...) and destructuring, but that's not convenient, or adding a Debug bound, but that leaks an implementation detail.

TomFryersMidsummer avatar Aug 21 '25 11:08 TomFryersMidsummer