mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Invert <CString as Deref>::deref
and CString::as_c_str
This is consistent with the style of `ByteString`.
This commit is contained in:
parent
a15cce2690
commit
f727b3622b
@ -574,7 +574,7 @@ impl CString {
|
||||
#[stable(feature = "as_c_str", since = "1.20.0")]
|
||||
#[rustc_diagnostic_item = "cstring_as_c_str"]
|
||||
pub fn as_c_str(&self) -> &CStr {
|
||||
&*self
|
||||
unsafe { CStr::from_bytes_with_nul_unchecked(self.as_bytes_with_nul()) }
|
||||
}
|
||||
|
||||
/// Converts this `CString` into a boxed [`CStr`].
|
||||
@ -705,14 +705,14 @@ impl ops::Deref for CString {
|
||||
|
||||
#[inline]
|
||||
fn deref(&self) -> &CStr {
|
||||
unsafe { CStr::from_bytes_with_nul_unchecked(self.as_bytes_with_nul()) }
|
||||
self.as_c_str()
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl fmt::Debug for CString {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt::Debug::fmt(&**self, f)
|
||||
fmt::Debug::fmt(self.as_c_str(), f)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user