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:
parent
6dc598a01b
commit
89f41839e4
@ -615,6 +615,14 @@ fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "os_string_fmt_write", since = "1.63.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.
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user