mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 02:57:37 +00:00
Implement Show for CString
We use use `from_utf8_lossy` to convert it to a MaybeOwned string, to avoid failing in case the CString contains invalid UTF-8
This commit is contained in:
parent
8836048c76
commit
6988bcd74c
@ -73,6 +73,7 @@ use collections::hash;
|
||||
use core::kinds::marker;
|
||||
use core::mem;
|
||||
use core::ptr;
|
||||
use core::fmt;
|
||||
use core::raw::Slice;
|
||||
use core::slice;
|
||||
use core::str;
|
||||
@ -344,6 +345,12 @@ impl Collection for CString {
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Show for CString {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
String::from_utf8_lossy(self.as_bytes_no_nul()).fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
/// A generic trait for converting a value to a CString.
|
||||
pub trait ToCStr {
|
||||
/// Copy the receiver into a CString.
|
||||
|
Loading…
Reference in New Issue
Block a user