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

Added generic iterator methods #341

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yankana
Copy link

@yankana yankana commented Nov 16, 2021

It's unnecessary to require allocated vectors instead of just any iterator. With this change, you can use with_labels_iter and with_notes_iter in the example code (and in other code) with arrays instead of vectors to avoid extra heap allocations. The other methods were left untouched so this isn't a breaking change.

It's unnecessary to require allocated vectors instead of just any iterator. With this change, you can use `with_labels_iter` in the example code (and in other code) with arrays instead of vectors to avoid extra heap allocations. The other methods were left untouched so this isn't a breaking change.
@Johann150
Copy link
Collaborator

Thanks for your contribution!

Since Vec<String> is compatible with impl IntoIterator<Item = String>, and likewise for the other function, I think we could even just replace the existing methods instead of creating new ones.

@yankana
Copy link
Author

yankana commented Nov 17, 2021

Since Vec<String> is compatible with impl IntoIterator<Item = String>, and likewise for the other function, I think we could even just replace the existing methods instead of creating new ones.

That would be a breaking change because changing a method from using a concrete type to a generic/opaque type would break code that relies on the compiler inferring the type to be a vector. Example:

// `collect::<Vec<String>>` is inferred here, but with `impl IntoIterator<Item = String>`, the compiler cannot infer
let diagnostic = Diagnostic::error().with_notes(string_iter.collect());

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.

None yet

2 participants