-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Implement [OsStr]::join #96744
Implement [OsStr]::join #96744
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1222,6 +1222,23 @@ impl OsStr { | |
} | ||
} | ||
|
||
#[unstable(feature = "slice_concat_ext", issue = "27747")] | ||
impl<S: Borrow<OsStr>> alloc::slice::Join<&OsStr> for [S] { | ||
type Output = OsString; | ||
|
||
fn join(slice: &Self, sep: &OsStr) -> OsString { | ||
let Some(first) = slice.first() else { | ||
return OsString::new(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't know the function existed, thanks! Feel free to file a PR. Ideally, one would make an optimized implementation like there is for str slices, but |
||
}; | ||
let first = first.borrow().to_owned(); | ||
slice[1..].iter().fold(first, |mut a, b| { | ||
a.push(sep); | ||
a.push(b.borrow()); | ||
a | ||
}) | ||
} | ||
} | ||
|
||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl Borrow<OsStr> for OsString { | ||
#[inline] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tracking issue #27747 was closed a while ago.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used the same tracking issue the other impl blocks for that trait have. The reason to close the tracking issue was because the feature is to be perma-unstable: #27747 (comment) . I'm not sure about changes in policy, but in the older times tracking issues for perma-unstable things would remain open indefinitely.