+++ /dev/null
-#![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("\"")
-}
+++ /dev/null
-use super::*;
-use crate::fmt::{Debug, Formatter, Result};
-
-#[test]
-fn smoke() {
- struct Helper<'a>(&'a [u8]);
-
- impl Debug for Helper<'_> {
- fn fmt(&self, f: &mut Formatter<'_>) -> Result {
- debug_fmt_bytestring(self.0, f)
- }
- }
-
- let input = b"\xF0hello,\tworld";
- let expected = r#""\xF0hello,\tworld""#;
- let output = format!("{:?}", Helper(input));
-
- assert!(output == expected);
-}
mod tests;
pub mod backtrace;
-pub mod bytestring;
pub mod condvar;
pub mod fs;
pub mod io;
//! systems: just a `Vec<u8>`/`[u8]`.
use crate::borrow::Cow;
-
use crate::fmt;
+use crate::fmt::Write;
use crate::mem;
use crate::rc::Rc;
use crate::str;
use crate::sync::Arc;
-use crate::sys_common::bytestring::debug_fmt_bytestring;
use crate::sys_common::{AsInner, IntoInner};
-use core::str::lossy::Utf8Lossy;
+use core::str::lossy::{Utf8Lossy, Utf8LossyChunk};
+
+#[cfg(test)]
+mod tests;
#[derive(Hash)]
#[repr(transparent)]
impl fmt::Debug for Slice {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
- debug_fmt_bytestring(&self.inner, formatter)
+ // Writes out a valid unicode string with the correct escape sequences
+
+ formatter.write_str("\"")?;
+ for Utf8LossyChunk { valid, broken } in Utf8Lossy::from_bytes(&self.inner).chunks() {
+ for c in valid.chars().flat_map(|c| c.escape_debug()) {
+ formatter.write_char(c)?
+ }
+
+ for b in broken {
+ write!(formatter, "\\x{:02X}", b)?;
+ }
+ }
+ formatter.write_str("\"")
}
}
--- /dev/null
+use super::*;
+
+#[test]
+fn slice_debug_output() {
+ let input = Slice::from_u8_slice(b"\xF0hello,\tworld");
+ let expected = r#""\xF0hello,\tworld""#;
+ let output = format!("{:?}", input);
+
+ assert_eq!(output, expected);
+}