Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions library/core/src/bstr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,7 @@ unsafe impl DerefPure for ByteStr {}
#[unstable(feature = "bstr", issue = "134915")]
impl fmt::Debug for ByteStr {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "\"")?;
for chunk in self.utf8_chunks() {
for c in chunk.valid().chars() {
match c {
'\0' => write!(f, "\\0")?,
'\x01'..='\x7f' => write!(f, "{}", (c as u8).escape_ascii())?,
_ => write!(f, "{}", c.escape_debug())?,
}
}
write!(f, "{}", chunk.invalid().escape_ascii())?;
}
write!(f, "\"")?;
Ok(())
fmt::Debug::fmt(&self.utf8_chunks().debug(), f)
}
}

Expand Down
22 changes: 2 additions & 20 deletions library/std/src/sys/os_str/bytes.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! The underlying OsString/OsStr implementation on Unix and many other
//! systems: just a `Vec<u8>`/`[u8]`.

use core::bstr::ByteStr;
use core::clone::CloneToUninit;

use crate::borrow::Cow;
use crate::collections::TryReserveError;
use crate::fmt::Write;
use crate::rc::Rc;
use crate::sync::Arc;
use crate::sys::{AsInner, FromInner, IntoInner};
Expand Down Expand Up @@ -64,25 +64,7 @@ impl fmt::Debug for Slice {

impl fmt::Display for Slice {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// If we're the empty string then our iterator won't actually yield
// anything, so perform the formatting manually
if self.inner.is_empty() {
return "".fmt(f);
}

for chunk in self.inner.utf8_chunks() {
let valid = chunk.valid();
// If we successfully decoded the whole chunk as a valid string then
// we can return a direct formatting of the string which will also
// respect various formatting flags if possible.
if chunk.invalid().is_empty() {
return valid.fmt(f);
}

f.write_str(valid)?;
f.write_char(char::REPLACEMENT_CHARACTER)?;
}
Ok(())
fmt::Display::fmt(ByteStr::from_bytes(&self.inner), f)
}
}

Expand Down
Loading