Skip to content

Implement SliceConcatExt for any iterable of string slices, not just Slice and Vec #1137

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

Open
BlacklightShining opened this issue May 30, 2015 · 3 comments
Labels
T-libs-api Relevant to the library API team, which will review and decide on the RFC.

Comments

@BlacklightShining
Copy link

Currently, these work (they both return "foo foo foo", as you'd expect):

["foo"; 3].connect(" ")
vec!["foo"; 3].connect(" ")

But these do not:

// type `collections::linked_list::LinkedList<&str>` does not implement any method in scope named `connect`
LinkedList::from_iter(repeat("foo").take(3)).connect(" ")
// type `core::iter::Take<core::iter::Repeat<&str>>` does not implement any method in scope named `connect`
repeat("foo").take(3).connect(" ")

Might std::slice::SliceConcatExt, be implemented for collections of and iterators over &strs?

@bluss
Copy link
Member

bluss commented May 30, 2015

I think coherence should allow it. Note that the slice versions iterate twice, to calculate the needed allocation exactly before concat. The iterator version can't do that, so it will be less efficient that way.

@gkoz
Copy link

gkoz commented May 31, 2015

Note that the slice versions iterate twice, to calculate the needed allocation exactly before concat. The iterator version can't do that, so it will be less efficient that way.

This got me thinking: if the ability to iterate twice is sufficient, could the methods be bounded on Self: Clone? This should preserve the efficiency while relaxing the requirements.

A quick and dirty POC.

@nrc nrc added the T-libs-api Relevant to the library API team, which will review and decide on the RFC. label Aug 29, 2016
@Centril
Copy link
Contributor

Centril commented Oct 7, 2018

Triage: no movement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-libs-api Relevant to the library API team, which will review and decide on the RFC.
Projects
None yet
Development

No branches or pull requests

5 participants