Skip to content

Commit 2eb798b

Browse files
committed
impl Display for CStr{,ing}
Delegate to `<ByteStr as Display>::fmt`. Link: rust-lang/libs-team#550 Link: #139984.
1 parent a15cce2 commit 2eb798b

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

Diff for: library/alloc/src/ffi/c_str.rs

+6
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,12 @@ impl fmt::Debug for CString {
716716
}
717717
}
718718

719+
impl fmt::Display for CString {
720+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
721+
fmt::Display::fmt(&**self, f)
722+
}
723+
}
724+
719725
#[stable(feature = "cstring_into", since = "1.7.0")]
720726
impl From<CString> for Vec<u8> {
721727
/// Converts a [`CString`] into a <code>[Vec]<[u8]></code>.

Diff for: library/core/src/ffi/c_str.rs

+6
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ impl fmt::Debug for CStr {
169169
}
170170
}
171171

172+
impl fmt::Display for CStr {
173+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
174+
fmt::Display::fmt(crate::bstr::ByteStr::from_bytes(self.to_bytes()), f)
175+
}
176+
}
177+
172178
#[stable(feature = "cstr_default", since = "1.10.0")]
173179
impl Default for &CStr {
174180
#[inline]

0 commit comments

Comments
 (0)