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

Update for stable Rust by removing the core feature #60

Merged
merged 1 commit into from
Apr 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ extern {
#[test]
fn should_box_and_unbox() {
use number::{CFNumber, number};
use std::num::ToPrimitive;

let arr = CFArray::from_CFTypes(&[
number(1).as_CFType(),
Expand All @@ -189,18 +188,18 @@ fn should_box_and_unbox() {
]);

unsafe {
let mut sum = 0i32;
let mut sum = 0;

for elem in arr.iter() {
let number: CFNumber = TCFType::wrap_under_get_rule(mem::transmute(elem));
sum += number.to_i32().unwrap()
sum += number.to_i64().unwrap()
}

assert!(sum == 15);

for elem in arr.iter() {
let number: CFNumber = TCFType::wrap_under_get_rule(mem::transmute(elem));
sum += number.to_i32().unwrap()
sum += number.to_i64().unwrap()
}

assert!(sum == 30);
Expand Down
3 changes: 1 addition & 2 deletions src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// except according to those terms.

use libc::{c_long, c_ulong, c_uint};
use std::num::Int;

pub type Boolean = u8;

Expand All @@ -26,7 +25,7 @@ pub trait CFIndexConvertible {
impl CFIndexConvertible for usize {
#[inline]
fn to_CFIndex(self) -> CFIndex {
let max_CFIndex: CFIndex = Int::max_value();
let max_CFIndex = CFIndex::max_value();
if self > (max_CFIndex as usize) {
panic!("value out of range")
}
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

#![allow(non_snake_case)]

#![feature(core)]

extern crate libc;

#[cfg(target_os="macos")]
Expand Down
38 changes: 10 additions & 28 deletions src/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use base::{TCFType, kCFAllocatorDefault};

use libc::c_void;
use std::mem;
use std::num::{FromPrimitive, ToPrimitive};

pub type CFNumberType = u32;

Expand Down Expand Up @@ -93,66 +92,49 @@ impl TCFType<CFNumberRef> for CFNumber {
}

// TODO(pcwalton): Floating point.
impl ToPrimitive for CFNumber {
impl CFNumber {
#[inline]
fn to_i64(&self) -> Option<i64> {
pub fn to_i64(&self) -> Option<i64> {
unsafe {
let mut value: i64 = 0;
let ok = CFNumberGetValue(self.obj, kCFNumberSInt64Type, mem::transmute(&mut value));
assert!(ok);
Some(value)
if ok { Some(value) } else { None }
}
}

#[inline]
fn to_u64(&self) -> Option<u64> {
// CFNumber does not support unsigned 64-bit values.
None
}

#[inline]
fn to_f64(&self) -> Option<f64> {
pub fn to_f64(&self) -> Option<f64> {
unsafe {
let mut value: f64 = 0.0;
let ok = CFNumberGetValue(self.obj, kCFNumberFloat64Type, mem::transmute(&mut value));
assert!(ok);
Some(value)
if ok { Some(value) } else { None }
}
}
}

// TODO(pcwalton): Floating point.
impl FromPrimitive for CFNumber {
#[inline]
fn from_i64(value: i64) -> Option<CFNumber> {
pub fn from_i64(value: i64) -> CFNumber {
unsafe {
let number_ref = CFNumberCreate(kCFAllocatorDefault,
kCFNumberSInt64Type,
mem::transmute(&value));
Some(TCFType::wrap_under_create_rule(number_ref))
TCFType::wrap_under_create_rule(number_ref)
}
}

#[inline]
fn from_u64(_: u64) -> Option<CFNumber> {
// CFNumber does not support unsigned 64-bit values.
None
}

#[inline]
fn from_f64(value: f64) -> Option<CFNumber> {
pub fn from_f64(value: f64) -> CFNumber {
unsafe {
let number_ref = CFNumberCreate(kCFAllocatorDefault,
kCFNumberFloat64Type,
mem::transmute(&value));
Some(TCFType::wrap_under_create_rule(number_ref))
TCFType::wrap_under_create_rule(number_ref)
}
}
}

/// A convenience function to create CFNumbers.
pub fn number(value: i64) -> CFNumber {
FromPrimitive::from_i64(value).unwrap()
CFNumber::from_i64(value)
}

#[link(name = "CoreFoundation", kind = "framework")]
Expand Down
2 changes: 1 addition & 1 deletion src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,5 +475,5 @@ fn string_and_back() {
let original = "The quick brown fox jumped over the slow lazy dog.";
let cfstr = CFString::from_static_string(original);
let converted = cfstr.to_string();
assert!(original == converted.as_slice());
assert!(converted == original);
}
2 changes: 1 addition & 1 deletion src/url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,5 +240,5 @@ fn file_url_from_path() {
let path = "/usr/local/foo/";
let cfstr_path = CFString::from_static_string(path);
let cfurl = CFURL::from_file_system_path(cfstr_path, kCFURLPOSIXPathStyle, true);
assert!("file:///usr/local/foo/" == cfurl.get_string().to_string().as_slice());
assert!(cfurl.get_string().to_string() == "file:///usr/local/foo/");
}