Closed
Description
The SliceConcatExt trait offers methods concat
and join
on slices. For somewhat technical reasons, it wasn't possible to make these inherent methods.
The methods themselves are stable, but the trait isn't. However, since the trait is in the prelude, the methods are usable in stable today.
Ideally, the methods would also be available on iterators, but there are performance ramifications for doing so. Impl specialization may help.
Metadata
Metadata
Assignees
Labels
Area: `[T]`Blocker: Implemented in the nightly compiler and unstable.Category: An issue tracking the progress of sth. like the implementation of an RFCLibs issues that are tracked on the team's project board.Relevant to the library API team, which will review and decide on the PR/issue.This PR / issue is in PFCP or FCP with a disposition to close it.The final comment period is finished for this PR / Issue.
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
teburd commentedon Nov 16, 2015
Having just run into needing this today it would be great to see the documentation for this referenced in the Vec docs with some examples
aturon commentedon Nov 18, 2015
@BFrog agreed. cc @steveklabnik
steveklabnik commentedon Nov 18, 2015
/cc #29380
oconnor663 commentedon Jan 23, 2016
@aturon just reading along, and I'm curious if you have time to explain: What are the technical reasons you mentioned at the top? Is this related to why the
SliceExt
trait exists?aturon commentedon Feb 2, 2016
@oconnor663
So, the main problem with moving to inherent methods at this point is that the traits provide something akin to method overloading -- both apply to slice types varying only by some bounds (
Clone
andBorrow
). I think originally they were less general, but there was some other holdup to making them inherent, which I no longer recall.re:
SliceExt
: the reason for that trait is somewhat obscure. Basically, thestd
crate ends up re-exporting a number of things from thecore
crate, but in the case of types like slices, it also wants to add methods of its own. We set things up so that the set of inherent methods for any type instd
has to be defined in exactly one of the crates making upstd
. Socore
's slices don't have any inherent items, because they're defined incollections
. You can find the impl here: http://static.rust-lang.org/doc/master/src/collections/slice.rs.html#160If you're just using
std
, you never need to see/work withSliceExt
. But if you're usingcore
, theSliceExt
trait is how we provide any methods on slices. It's in the core prelude, so you generally don't notice the difference.... Hope that helps!
oconnor663 commentedon Feb 2, 2016
Good to know :)
Dr-Emann commentedon Apr 17, 2017
It's kinda annoying to be able to join strings with a str (which can have multiple chars), but joining a slice of slices, you can only join with a single element.
e.g.
works, but
doesn't work
leoyvens commentedon Sep 12, 2017
I tried making the methods inherent with separate inherent impls. But we can't have multiple inherent impls for a primitive. I got the error:
"only a single inherent implementation marked with
#[lang = "slice"]
is allowed for the[T]
primitive"This is known of course, the issue is #32631.
SimonSapin commentedon Apr 1, 2018
@leodasvacas I think you mean multiple
impl Type {…}
blocks, but that’s not the main issue. We can add new methods in the existing impl blocks. However in this case, for example<&[String]>::concat
and<&[Vec<T>]>::concat
end up being the same method, so a helper trait would still be needed to generalize over both cases.The libs team discussed this and consensus was to add
#[doc(hidden)]
to the deprecated (but stable)connect
method, but make no further changes or stabilize anything at the moment. Inherent methods with a new helper trait doesn’t seem much better than the current trait methods, and still wouldn’t help with joining/concatenating iterators without first collecting into an intermediateVec
.Design proposals to generalize this functionality to iterators are welcome.
sanmai-NL commentedon Sep 6, 2018
Does this mean
concat()
isn’t usable in ano_std
module with explicitstd
imports and without theslice_concat_ext
unstable feature enabled?SimonSapin commentedon Sep 6, 2018
@sanmai-NL That is correct. (Modulo #15702, which is a bug and not considered part of the stability promise.)
BurntSushi commentedon Jan 14, 2019
Does there exist a path to stabilizing
SliceConcatExt
? Are there any specific outstanding issues associated with it? The specific use case I have for it is that I'd like for it to be able to work on other string types. e.g.,The work-around is to define a separate trait that is probably identical to
SliceConcatExt
, but in my crate. But that means users won't benefit from having it in the prelude.36 remaining items
rfcbot commentedon Oct 28, 2021
The final comment period, with a disposition to close, as per the review above, is now complete.
As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.
jplatte commentedon Mar 1, 2022
This issue is still referenced in at least two
#[unstable]
attributes here:rust/library/alloc/src/str.rs
Line 78 in f0c4da4
It seems like those need to be rewritten, right?
kornelski commentedon Nov 24, 2022
Is there a need for this trait to use
Borrow
rather thanAsRef
? The documentation forBorrow
recommends usingAsRef
whenEq
/Ord
equivalence isn't required.thomcc commentedon Nov 24, 2022
That does sound like a mistake, but changing it now sounds impossible to do without breaking code.
acksly commentedon Apr 11, 2025
Up #27747 (comment)
Is there a reason for that ?
Maybe document it or open a new issue for it to be unstable rather than referencing a closed PR in the documentation maybe ?