summaryrefslogtreecommitdiffstats
path: root/safe_libc/src/string.rs
diff options
context:
space:
mode:
Diffstat (limited to 'safe_libc/src/string.rs')
-rw-r--r--safe_libc/src/string.rs12
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,
))
)