about summary refs log tree commit diff
path: root/library/std/src/sys_common/bytestring.rs
diff options
context:
space:
mode:
authorYuki Okushi <jtitor@2k36.org>2021-07-03 03:15:09 +0900
committerGitHub <noreply@github.com>2021-07-03 03:15:09 +0900
commitfb736d96c33702f1aabac4092003c412c1d9d00a (patch)
tree63141520596cbabde8ff5570538e8056322011eb /library/std/src/sys_common/bytestring.rs
parent45470a3bcd9f26017bcdbf4d5ae07be0d922ce93 (diff)
parent059008f0334fc3086f541da3c1e5729cc7b53a7c (diff)
Rollup merge of #85001 - CDirkx:bytestring, r=JohnTitor
Merge `sys_common::bytestring` back into `os_str_bytes`

`bytestring` contains code for correctly debug formatting a byte slice (`[u8]`). This functionality is and has historically only been used to provide the debug formatting of byte-based os-strings (on unix etc.).

Having this functionality in the separate `bytestring` module was useful in the past to reduce duplication, as [when it was added](https://github.com/rust-lang/rust/pull/46798) `os_str_bytes` was still split into `sys::{unix, redox, wasi, etc.}::os_str`. However, now that is no longer the case, there is not much reason for the `bytestring` functionality to be separate from `os_str_bytes`; I don't think it is very likely that another part of std will need to handle formatting byte strings that are not os-strings in the future (everything should be `utf8`). This is why this PR merges the functionality of `bytestring` directly into the debug implementation in `os_str_bytes`.
Diffstat (limited to 'library/std/src/sys_common/bytestring.rs')
-rw-r--r--library/std/src/sys_common/bytestring.rs26
1 files changed, 0 insertions, 26 deletions
diff --git a/library/std/src/sys_common/bytestring.rs b/library/std/src/sys_common/bytestring.rs
deleted file mode 100644
index 97fba60c271..00000000000
--- a/library/std/src/sys_common/bytestring.rs
+++ /dev/null
@@ -1,26 +0,0 @@
-#![allow(dead_code)]
-
-#[cfg(test)]
-mod tests;
-
-use crate::fmt::{Formatter, Result, Write};
-use core::str::lossy::{Utf8Lossy, Utf8LossyChunk};
-
-pub fn debug_fmt_bytestring(slice: &[u8], f: &mut Formatter<'_>) -> Result {
-    // Writes out a valid unicode string with the correct escape sequences
-    fn write_str_escaped(f: &mut Formatter<'_>, s: &str) -> Result {
-        for c in s.chars().flat_map(|c| c.escape_debug()) {
-            f.write_char(c)?
-        }
-        Ok(())
-    }
-
-    f.write_str("\"")?;
-    for Utf8LossyChunk { valid, broken } in Utf8Lossy::from_bytes(slice).chunks() {
-        write_str_escaped(f, valid)?;
-        for b in broken {
-            write!(f, "\\x{:02X}", b)?;
-        }
-    }
-    f.write_str("\"")
-}