1
Fork 0

Rollup merge of #97915 - tbu-:pr_os_string_fmt_write, r=joshtriplett

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());
```
This commit is contained in:
Yuki Okushi 2022-07-17 13:08:48 +09:00 committed by GitHub
commit 48cf43b752
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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 { impl OsStr {
/// Coerces into an `OsStr` slice. /// Coerces into an `OsStr` slice.
/// ///