From de9bc974a6b423b7f086af23e50c47a097dcd352 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 4 Apr 2020 17:13:36 +0200 Subject: Minor cleanup, implement Debug, Display for CBox --- safe_libc/src/string.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'safe_libc/src/string.rs') 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, )) ) -- cgit v1.2.3