diff options
| author | Yuki Okushi <jtitor@2k36.org> | 2022-07-17 13:08:48 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-17 13:08:48 +0900 |
| commit | 48cf43b752282d512be1a1cb664166698b5d63a8 (patch) | |
| tree | d62e2d66de4bddb74046682c01cdd656ab671aed | |
| parent | 353d0180bb044a99178daa99e394c7ca3c1ebf48 (diff) | |
| parent | 3855e868738a847f1e38a6157590aa1a197604ea (diff) | |
| download | rust-48cf43b752282d512be1a1cb664166698b5d63a8.tar.gz rust-48cf43b752282d512be1a1cb664166698b5d63a8.zip | |
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());
```
| -rw-r--r-- | library/std/src/ffi/os_str.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs index f2bbcc85cec..a0a5c003d28 100644 --- a/library/std/src/ffi/os_str.rs +++ b/library/std/src/ffi/os_str.rs @@ -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. /// |
