Add Iterator::intersperse by jonas-schievink · Pull Request #75784 · rust-lang/rust (original) (raw)
So, I'm the current maintainer of Itertools. I'm thrilled to see this PR! Intersperse
is widely useful, and very deserving of being a method on Iterator
. My very first PR to Itertools was actually optimizing Intersperse::fold
, because chain
s of Intersperse
ed tokens are widespread in the internals of the standard proc macro libraries.
I personally suspect that it might not be a good idea to land this given the itertools conflict
I really wouldn't want Itertools to get in the way of a good addition. As an Itertools user, the fixes for these sorts of conflicts are pretty simple: you just used the fully-qualified method call syntax, or limit the scope of your import of Itertools
so that your call to libcore's intersperse
is unaffected. (For the uninitiated, the introduction of Iterator::flatten
caused the same issues. I don't think it posed much more than a minor inconvenience.)
It's only as an Itertools maintainer that these sorts of conflicts cause me a real headache. I really don't like that our README has to discourage contributions to minimize these sorts of issues, and I don't like not merging PRs that seem so useful that I can foresee them making their way into Iterator
.
On that note, our upcoming 0.10.0 release is going to include intersperse_with, a generalized form of intersperse
. If Iterator
is going to gain intersperse
, it doesn't seem out of the question that it might want intersperse_with
too. Should I cut it from the release to avoid a potential future conflict?
in the future at least: itertools could have #[cfg(not(rust_has_intersperse))] on its extension trait method, set in build.rs via something like https://docs.rs/autocfg/1.0.1/autocfg/
This seems promising(!!!), but maybe a little unpleasant for contributors. Any new, non-allocating method added to Itertools
poses a potential future conflict with Itertools
. We'd need to test for every such method name in our build.rs
. I'd much prefer a permanent solution to this problem.