Skip to content

Commit 89f4183

Browse files
committed
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()); ```
1 parent 6dc598a commit 89f4183

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
@@ -615,6 +615,14 @@ impl Hash for OsString {
615615
}
616616
}
617617

618+
#[stable(feature = "os_string_fmt_write", since = "1.63.0")]
619+
impl fmt::Write for OsString {
620+
fn write_str(&mut self, s: &str) -> fmt::Result {
621+
self.push(s);
622+
Ok(())
623+
}
624+
}
625+
618626
impl OsStr {
619627
/// Coerces into an `OsStr` slice.
620628
///

0 commit comments

Comments
 (0)