Auto merge of #254 - sibsibsib:master, r=jdm

to_i32 shortcut for CFNumber

kCFNumberIntType is needed in some iokit APIs.

Please let me know if you think anything is missing.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-foundation-rs/254)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo
2018-09-23 20:20:21 -04:00
committed by GitHub
+10
View File
@@ -25,6 +25,16 @@ impl_CFTypeDescription!(CFNumber);
impl_CFComparison!(CFNumber, CFNumberCompare);
impl CFNumber {
#[inline]
pub fn to_i32(&self) -> Option<i32> {
unsafe {
let mut value: i32 = 0;
let ok = CFNumberGetValue(self.0, kCFNumberSInt32Type, mem::transmute(&mut value));
if ok { Some(value) } else { None }
}
}
#[inline]
pub fn to_i64(&self) -> Option<i64> {
unsafe {