diff options
| author | Tamir Duberstein <tamird@gmail.com> | 2025-04-18 10:15:11 -0400 |
|---|---|---|
| committer | Tamir Duberstein <tamird@gmail.com> | 2025-04-18 10:31:12 -0400 |
| commit | f727b3622bf69f44500e708f387160d5afbb39db (patch) | |
| tree | e8327431f03ba1c76e6e47d4c82bf6afde9e16d4 | |
| parent | a15cce2690e8fab72422515c9dc02c6fbc506733 (diff) | |
| download | rust-f727b3622bf69f44500e708f387160d5afbb39db.tar.gz rust-f727b3622bf69f44500e708f387160d5afbb39db.zip | |
Invert `<CString as Deref>::deref` and `CString::as_c_str`
This is consistent with the style of `ByteString`.
| -rw-r--r-- | library/alloc/src/ffi/c_str.rs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/library/alloc/src/ffi/c_str.rs b/library/alloc/src/ffi/c_str.rs index f6743c65710..7e863f13f43 100644 --- a/library/alloc/src/ffi/c_str.rs +++ b/library/alloc/src/ffi/c_str.rs @@ -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) } } |
