Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernization and cleanup #69

Merged
merged 8 commits into from Sep 5, 2015
Merged

Clean up data

* Implement Deref for CFData
* Use slice::from_raw_parts instead of transmuting a tuple
  • Loading branch information
sfackler committed Aug 29, 2015
commit 4e7286ecc16a27abf4b87c582881f3919409bbb7
@@ -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 {
/*
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.