Skip to content

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

Open

Description

@BlacklightShining

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?

Activity

  1. bluss commented on May 30, 2015

    @bluss

    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.

  2. gkoz commented on May 31, 2015

    @gkoz

    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.

  3. added
    T-libs-api
    on Aug 29, 2016
  4. Centril commented on Oct 7, 2018

    @Centril
    Contributor

    Triage: no movement.

  5. removed
    T-libs-api
    on Aug 18, 2026
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

    T-libs

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions