-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Libs: Unify concat and concat_vec #18561
Conversation
We've long had traits `StrVector` and `VectorVector` providing `concat`/`connect` and `concat_vec`/`connect_vec` respectively. The reason for the distinction is that coherence rules did not used to be robust enough to allow impls on e.g. `Vec<String>` versus `Vec<&[T]>`. This PR consolidates the traits into a single `Concat` trait provided by `slice` and the preldue (where it replaces `StrVector`, which is removed.) The `VectorVector` trait is retained in deprecated form. [breaking-change]
The name |
FWIW, I've been thinking that these might be better as freestanding functions that then take iterator, e.g. impl String {
fn concat<S, It>(iter: It) -> String
where S: Str, It: Iterator<S> { ... }
} This avoids one having to allocate a temporary vector. I guess it may cost the performance gained by preallocation. |
@huonw We could probably even set up yet another overload of The approach you're suggesting is very slightly less ergonomic (though it would be better with I'm basically happy to go in any of these directions; I mostly just want pinging @alexcrichton for thoughts. |
Update: @huonw and I chatted a bit on IRC, and feel that the That said, I think we can/should land this PR as-is as an incremental improvement, and do some performance testing with the iterator approach. That will also involve adding an additional adapter method like the previously-proposed |
I'm a huge fan of pushing as much as possible into I do agree with @huonw though that when concatenating items I find myself more often than not collecting an iterator into a This is also borderline "one extra superfluous trait" in the stdlib as it seems to largely just be adding methods to slices? I suppose I'd be more in favor of what @huonw suggested with |
ping @aturon |
Closing in favor of an iterator-based proposal. |
…variable Add macro expansion test for raw variable names
We've long had traits
StrVector
andVectorVector
providingconcat
/connect
andconcat_vec
/connect_vec
respectively. Thereason for the distinction is that coherence rules did not used to be
robust enough to allow impls on e.g.
Vec<String>
versusVec<&[T]>
.This PR consolidates the traits into a single
Concat
trait provided byslice
and the preldue (where it replacesStrVector
, which isremoved.)
The
VectorVector
trait is retained in deprecated form.[breaking-change]