Skip to content

Commit

Permalink
Rollup merge of #97915 - tbu-:pr_os_string_fmt_write, r=joshtriplett
Browse files Browse the repository at this point in the history
Implement `fmt::Write` for `OsString`

This allows to format into an `OsString` without unnecessary
allocations. E.g.

```
let mut temp_filename = path.into_os_string();
write!(&mut temp_filename, ".tmp.{}", process::id());
```
  • Loading branch information
JohnTitor authored Jul 17, 2022
2 parents 353d018 + 3855e86 commit 48cf43b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions library/std/src/ffi/os_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,14 @@ impl Hash for OsString {
}
}

#[stable(feature = "os_string_fmt_write", since = "1.64.0")]
impl fmt::Write for OsString {
fn write_str(&mut self, s: &str) -> fmt::Result {
self.push(s);
Ok(())
}
}

impl OsStr {
/// Coerces into an `OsStr` slice.
///
Expand Down

0 comments on commit 48cf43b

Please sign in to comment.