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

Why itertools is not part of STD? #617

Closed
Wandalen opened this issue May 24, 2022 · 5 comments
Closed

Why itertools is not part of STD? #617

Wandalen opened this issue May 24, 2022 · 5 comments

Comments

@Wandalen
Copy link
Contributor

Wandalen commented May 24, 2022

Crate itertools implements a lot of useful and often essential algorithms based on pattern iterator, extending STD.
Why is it not part of STD?
Is there reason why it should be not a part of STD?
Is that harmful to have in STD something what is not totally necessary?

@hellow554
Copy link
Contributor

One reason, quoting the docs:

However, if your feature involves heap allocation, such as storing elements in a Vec<T>, then it can't be accepted into libcore, and you should propose it for itertools directly instead.

@Wandalen
Copy link
Contributor Author

Wandalen commented Jun 2, 2022

I see. I believe most things from the crate should be in std.

@scottmcm
Copy link
Contributor

scottmcm commented Jun 2, 2022

I suggest closing this issue, since it's not really specific enough to ever close, and the OP also asked it in a URLO thread: https://users.rust-lang.org/t/why-itertools-is-not-part-of-std/76016/27?u=scottmcm

To copy my reply to here:

The core answer is that itertools can make breaking changes, but std cannot.

That means that anything we add to Iterator we're stuck with in exactly that form forever. And since most of the provided things have no need to be overridden, there's no need to have them in core, so they might as well be in another crate if there's any question about it.

One common situation where that happens is things that might want lending iterators (formerly streaming iterators) in the future. For example, group_by says

This type implements IntoIterator (it is not an iterator itself), because the group iterators need to borrow from this value. It should be stored in a local variable or temporary and iterated.

So it's plausible that std doesn't want that right now, because it wants to leave the API space available for something that can be a (lending) iterator, once such a thing is possible.

Also, a bunch of the itertools things need extra types, not just the method on iterator. Things like MinMaxResult and EitherOrBoth are important for making some of them work, but it's not clear that core wants to have those.

@jswrenn
Copy link
Member

jswrenn commented Jun 2, 2022

That's an excellent answer! I also want to add: Things in itertools sometimes do make their way over to libcore! If I had my druthers, it'd happen more often. Unfortunately, because itertools is so widely used, adding methods with the same name to Iterator can cause widespread breakage.

@jswrenn jswrenn closed this as completed Jun 2, 2022
@Wandalen
Copy link
Contributor Author

Wandalen commented Jun 2, 2022

Sure. Thanks for answer.

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

4 participants