Skip to content

Tracking issue for slice_concat_ext stabilization #27747

Closed
@aturon

Description

@aturon
Member

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.

Activity

added
T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.
B-unstableBlocker: Implemented in the nightly compiler and unstable.
on Aug 12, 2015
teburd

teburd commented on Nov 16, 2015

@teburd

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

aturon commented on Nov 18, 2015

@aturon
MemberAuthor
steveklabnik

steveklabnik commented on Nov 18, 2015

@steveklabnik
Member

/cc #29380

oconnor663

oconnor663 commented on Jan 23, 2016

@oconnor663
Contributor

@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

aturon commented on Feb 2, 2016

@aturon
MemberAuthor

@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 and Borrow). 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, the std crate ends up re-exporting a number of things from the core 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 in std has to be defined in exactly one of the crates making up std. So core's slices don't have any inherent items, because they're defined in collections. You can find the impl here: http://static.rust-lang.org/doc/master/src/collections/slice.rs.html#160

If you're just using std, you never need to see/work with SliceExt. But if you're using core, the SliceExt 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

oconnor663 commented on Feb 2, 2016

@oconnor663
Contributor

Good to know :)

Dr-Emann

Dr-Emann commented on Apr 17, 2017

@Dr-Emann

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.

let v = vec!["1", "2", "3"];
v.join(", ")

works, but

let v: Vec<&[u8]> = vec![b"1", b"2", b"3"];
v.join(b", ") // Error: expected u8, found array of 2 elements
v.join(&b',') // works, but is missing the space char

doesn't work

added
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
on Jul 22, 2017
leoyvens

leoyvens commented on Sep 12, 2017

@leoyvens
Contributor

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

SimonSapin commented on Apr 1, 2018

@SimonSapin
Contributor

@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 intermediate Vec.

Design proposals to generalize this functionality to iterators are welcome.

sanmai-NL

sanmai-NL commented on Sep 6, 2018

@sanmai-NL

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.

Does this mean concat() isn’t usable in a no_std module with explicit std imports and without the slice_concat_ext unstable feature enabled?

SimonSapin

SimonSapin commented on Sep 6, 2018

@SimonSapin
Contributor

@sanmai-NL That is correct. (Modulo #15702, which is a bug and not considered part of the stability promise.)

BurntSushi

BurntSushi commented on Jan 14, 2019

@BurntSushi
Member

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.,

impl<S: Borrow<BStr>> SliceConcatExt for [S] {
    type Output = BString;
    // ...
}

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

added
final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.
and removed
proposed-final-comment-periodProposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off.
on Oct 18, 2021
added and removed
final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.
on Oct 28, 2021
rfcbot

rfcbot commented on Oct 28, 2021

@rfcbot
Collaborator

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

jplatte commented on Mar 1, 2022

@jplatte
Contributor

This issue is still referenced in at least two #[unstable] attributes here:

#[unstable(feature = "slice_concat_ext", issue = "27747")]

It seems like those need to be rewritten, right?

kornelski

kornelski commented on Nov 24, 2022

@kornelski
Contributor

Is there a need for this trait to use Borrow rather than AsRef? The documentation for Borrow recommends using AsRef when Eq/Ord equivalence isn't required.

thomcc

thomcc commented on Nov 24, 2022

@thomcc
Member

That does sound like a mistake, but changing it now sounds impossible to do without breaking code.

acksly

acksly commented on Apr 11, 2025

@acksly

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-sliceArea: `[T]`B-unstableBlocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCLibs-TrackedLibs issues that are tracked on the team's project board.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.disposition-closeThis PR / issue is in PFCP or FCP with a disposition to close it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @steveklabnik@kornelski@teburd@Amanieu@SimonSapin

        Issue actions

          Tracking issue for `slice_concat_ext` stabilization · Issue #27747 · rust-lang/rust