Generic slice join

Hi guys,

Is it possible to implement a generic method that could join slices of different types?
In my case I want &[str], &[Path], &[String]


I could make it generic over an Iterator and write my own join, but I wonder if it's possible to utilize an existing [T]::join ( which is using unstable Join trait)


Path might contain non-UTF-8 data, so it cannot be trivially converted to String. However, it would be possible for the standard library to add a Join implementation that outputs an OsString.

This open issue is closely related:

I'm not sure if this solves your problem entirely, but str, Path, and String all implement AsRef<Path>.

I couldn't make slice::join to work generically, and wrote this instead:

fn join_paths<I>(files: I) -> String
    where I: IntoIterator,
          I::Item: AsRef<Path>
    let mut buf = String::new();
    let mut iter = files.into_iter().peekable();
    while let Some(n) = {
        if iter.peek().is_some() {

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.