Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trait Iterator not implemented for NonEmptyIterator? #25

Open
alexdewar opened this issue Jul 24, 2024 · 2 comments
Open

Trait Iterator not implemented for NonEmptyIterator? #25

alexdewar opened this issue Jul 24, 2024 · 2 comments

Comments

@alexdewar
Copy link

I'm currently getting the warning below when using the nonempty-collections crate. If I modify my code to return an impl Iterator instead of an impl NonEmptyIterator it works fine. If you could shed any light on this that would be great. I'm happy to provide more code if that would be helpful.

    Checking muse2 v2.0.0-dev1 (/home/alex/code/MUSE_2.0)
error[E0277]: `impl nonempty_collections::NonEmptyIterator<Item = Result<_, input::InputError>> + '_` is not an iterator
   --> src/process.rs:245:19
    |
245 |     for result in read_csv(&file_path)? {
    |                   ^^^^^^^^^^^^^^^^^^^^^ `impl nonempty_collections::NonEmptyIterator<Item = Result<_, input::InputError>> + '_` is not an iterator
    |
    = help: the trait `Iterator` is not implemented for `impl nonempty_collections::NonEmptyIterator<Item = Result<_, input::InputError>> + '_`, which is required by `impl nonempty_collections::NonEmptyIterator<Item = Result<_, input::InputError>> + '_: IntoIterator`
    = note: required for `impl nonempty_collections::NonEmptyIterator<Item = Result<_, input::InputError>> + '_` to implement `IntoIterator`
@fosskers
Copy link
Owner

fosskers commented Jul 24, 2024

Hi, thanks for the report. I believe this is happening because while any specific instance of a NonEmptyIterator chain can be automatically converted into an Iterator when used in for, an opaque NonEmptyIterator cannot. There doesn't seem to be a blanket implementation that says "all NonEmptyIterators are obviously Iterators". This is something to look into.

In the meantime, you can work around the issue as you've described. Since you're consuming the entire thing in a for here, the guarantee of non-emptiness doesn't seem to matter here (without knowing more about your code).

@alexdewar
Copy link
Author

Interesting. Thanks for your insight!

Unfortunately in my case I'd still like to be able to guarantee that my for loop runs at least once, so a NonEmptyIterator would be handy here. Still, I can work round this.

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

No branches or pull requests

2 participants