diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2020-04-04 17:13:36 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2020-04-04 17:13:36 +0200 |
commit | de9bc974a6b423b7f086af23e50c47a097dcd352 (patch) | |
tree | 9e362c5eaebf76b83727b40fecbf5cbc456665db /safe_libc/src/string.rs | |
parent | f0b3d5166ef1255fac880b146875ef46d2599a13 (diff) | |
download | neco-de9bc974a6b423b7f086af23e50c47a097dcd352.tar neco-de9bc974a6b423b7f086af23e50c47a097dcd352.zip |
Minor cleanup, implement Debug, Display for CBox
Diffstat (limited to 'safe_libc/src/string.rs')
-rw-r--r-- | safe_libc/src/string.rs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/safe_libc/src/string.rs b/safe_libc/src/string.rs index c85f788..8f973ad 100644 --- a/safe_libc/src/string.rs +++ b/safe_libc/src/string.rs @@ -12,7 +12,7 @@ pub struct CStr { inner: libc::c_char } impl CStr { #[inline] pub unsafe fn from_ptr_unchecked<'a>(p: *const libc::c_char) -> &'a CStr { - &*(p as *const CStr) + &*p.cast() } #[inline] @@ -23,7 +23,7 @@ impl CStr { #[inline] pub unsafe fn from_mut_ptr_unchecked<'a>(p: *mut libc::c_char) -> &'a mut CStr { - &mut *(p as *mut CStr) + &mut *p.cast() } #[inline] @@ -34,7 +34,7 @@ impl CStr { #[inline] pub unsafe fn from_bytes_with_nul_unchecked(bytes: &[u8]) -> &CStr { - CStr::from_ptr_unchecked(bytes.as_ptr() as *const libc::c_char) + CStr::from_ptr_unchecked(bytes.as_ptr().cast()) } // TODO @@ -59,7 +59,7 @@ impl CStr { #[inline] pub fn as_bytes(&self) -> &[u8] { unsafe { slice::from_raw_parts( - self.as_ptr() as *const u8, + self.as_ptr().cast(), self.len(), ) } } @@ -67,7 +67,7 @@ impl CStr { #[inline] pub fn as_mut_bytes(&mut self) -> &mut [u8] { unsafe { slice::from_raw_parts_mut( - self.as_mut_ptr() as *mut u8, + self.as_mut_ptr().cast(), self.len(), ) } } @@ -126,7 +126,7 @@ impl From<&[u8]> for CString { unsafe { CString::from_raw_unchecked( util::must_succeed(libc::strndup( - s.as_ptr() as *const libc::c_char, + s.as_ptr().cast(), s.len() as libc::size_t, )) ) |