Clean up data

* Implement Deref for CFData
* Use slice::from_raw_parts instead of transmuting a tuple
This commit is contained in:
Steven Fackler
2015-08-29 15:40:25 -07:00
parent 0d216f2e33
commit 4e7286ecc1
+12 -1
View File
@@ -13,6 +13,8 @@ use base::{CFAllocatorRef, CFIndex, CFIndexConvertible, CFRelease, CFRetain};
use base::{CFTypeID, CFTypeRef, TCFType, kCFAllocatorDefault};
use std::mem;
use std::ops::Deref;
use std::slice;
#[repr(C)]
struct __CFData;
@@ -82,7 +84,7 @@ impl CFData {
#[inline]
pub fn bytes<'a>(&'a self) -> &'a [u8] {
unsafe {
mem::transmute((CFDataGetBytePtr(self.obj), self.len() as usize))
slice::from_raw_parts(CFDataGetBytePtr(self.obj), self.len() as usize)
}
}
@@ -95,6 +97,15 @@ impl CFData {
}
}
impl Deref for CFData {
type Target = [u8];
#[inline]
fn deref(&self) -> &[u8] {
self.bytes()
}
}
#[link(name = "CoreFoundation", kind = "framework")]
extern {
/*