Skip to content

ExactlyOneError doesn't always implement Debug #1052

@TomFryersMidsummer

Description

@TomFryersMidsummer

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions