<!-- Thank you for creating a tracking issue! 📜 Tracking issues are for tracking a feature from implementation to stabilisation. Make sure to include the relevant RFC for the feature if it has one. Otherwise provide a short summary of the feature and link any relevant PRs or issues, and remove any sections that are not relevant to the feature. Remember to add team labels to the tracking issue. For a language team feature, this would e.g., be `T-lang`. Such a feature should also be labeled with e.g., `F-my_feature`. This label is used to associate issues (e.g., bugs and design questions) to the feature. --> This tracking issue is to create a more ergonomic method to `join` on `Iterator` without collect. Hopefully, we can do some optimizations on top of it but I haven't think of any case to improve it. The feature gate for the issue is `#![feature(iterator_join)]`. Before ```rust ["hello", "world"].iter().collect::<Vec<_>>().join(" ") ``` After ```rust ["hello", "world"].iter().join(" ") ``` It makes use of `Join` under `slice_concat_trait` feature https://github.com/rust-lang/rust/issues/27747 and have a similar behavior to `Iterator::collect`. It is similar to `join` from `itertools` except that it makes use of the stuff mentioned for feature parity between `Iterator` and `join` and ergonomics to not need to do `.collect::<Vec<_>>()`. Technical implementation proof of concept. ```rust pub fn join<T, Separator>(iter: impl Iterator<Item = T>, sep: Separator) -> <[T] as Join<Separator>>::Output where [T]: Join<Separator>, { // <[S] as std::slice::Join<&str>> // <[V] as std::slice::Join<&T>> // <[V] as std::slice::Join<&[T]>> Join::join(iter.collect::<Vec<T>>().as_slice(), sep) } ``` Existing discussion on zulip https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/join.20on.20Iterator Related issue https://github.com/rust-lang/rust/issues/22754 ### About tracking issues Tracking issues are used to record the overall progress of implementation. They are also uses as hubs connecting to other relevant issues, e.g., bugs or open design questions. A tracking issue is however *not* meant for large scale discussion, questions, or bug reports about a feature. Instead, open a dedicated issue for the specific matter and add the relevant feature gate label. ### Steps <!-- Include each step required to complete the feature. Typically this is a PR implementing a feature, followed by a PR that stabilises the feature. However for larger features an implementation could be broken up into multiple PRs. --> - [ ] Implement the RFC (cc @rust-lang/T-libs @Amanieu @cuviper) - https://github.com/rust-lang/rust/pull/75738 - [ ] Adjust documentation ([see instructions on rustc-dev-guide][doc-guide]) - [ ] Stabilization PR ([see instructions on rustc-dev-guide][stabilization-guide]) [stabilization-guide]: https://rustc-dev-guide.rust-lang.org/stabilization_guide.html#stabilization-pr [doc-guide]: https://rustc-dev-guide.rust-lang.org/stabilization_guide.html#documentation-prs ### Unresolved Questions <!-- Include any open questions that need to be answered before the feature can be stabilised. --> - [ ] Figure out potential performance improvements CC @lzutao - [ ] Add clippy lint to use `.join(sep)` rather than `.collect::<Vec<_>>().join()` after stabilization? Is it even possible when it goes across lines? ### Implementation history <!-- Include a list of all the PRs that were involved in implementing the feature. --> - Initial Implementation: WIP (please let me do this)