Skip to content

Commit 48cf43b

Browse files
authored
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()); ```
2 parents 353d018 + 3855e86 commit 48cf43b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

library/std/src/ffi/os_str.rs

+8
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,14 @@ impl Hash for OsString {
643643
}
644644
}
645645

646+
#[stable(feature = "os_string_fmt_write", since = "1.64.0")]
647+
impl fmt::Write for OsString {
648+
fn write_str(&mut self, s: &str) -> fmt::Result {
649+
self.push(s);
650+
Ok(())
651+
}
652+
}
653+
646654
impl OsStr {
647655
/// Coerces into an `OsStr` slice.
648656
///

0 commit comments

Comments
 (0)