Auto merge of #77 - sfackler:error, r=pcwalton
Add CFError support <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-foundation-rs/77) <!-- Reviewable:end -->
This commit is contained in:
@@ -34,7 +34,7 @@ pub struct CFArrayCallBacks {
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
struct __CFArray(c_void);
|
||||
pub struct __CFArray(c_void);
|
||||
|
||||
pub type CFArrayRef = *const __CFArray;
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ use base::CFTypeID;
|
||||
use string::CFStringRef;
|
||||
|
||||
#[repr(C)]
|
||||
struct __CFBundle(c_void);
|
||||
pub struct __CFBundle(c_void);
|
||||
|
||||
pub type CFBundleRef = *const __CFBundle;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ use libc::c_void;
|
||||
use base::{CFAllocatorRef, CFTypeID, CFIndex};
|
||||
|
||||
#[repr(C)]
|
||||
struct __CFData(c_void);
|
||||
pub struct __CFData(c_void);
|
||||
|
||||
pub type CFDataRef = *const __CFData;
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ pub struct CFDictionaryValueCallBacks {
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
struct __CFDictionary(c_void);
|
||||
pub struct __CFDictionary(c_void);
|
||||
|
||||
pub type CFDictionaryRef = *const __CFDictionary;
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
// Copyright 2016 The Servo Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use libc::c_void;
|
||||
|
||||
use base::{CFTypeID, CFIndex};
|
||||
use string::CFStringRef;
|
||||
|
||||
#[repr(C)]
|
||||
pub struct __CFError(c_void);
|
||||
|
||||
pub type CFErrorRef = *mut __CFError;
|
||||
|
||||
extern "C" {
|
||||
pub fn CFErrorGetTypeID() -> CFTypeID;
|
||||
|
||||
pub static kCFErrorDomainPOSIX: CFStringRef;
|
||||
pub static kCFErrorDomainOSStatus: CFStringRef;
|
||||
pub static kCFErrorDomainMach: CFStringRef;
|
||||
pub static kCFErrorDomainCocoa: CFStringRef;
|
||||
|
||||
pub fn CFErrorGetDomain(err: CFErrorRef) -> CFStringRef;
|
||||
pub fn CFErrorGetCode(err: CFErrorRef) -> CFIndex;
|
||||
|
||||
pub fn CFErrorCopyDescription(err: CFErrorRef) -> CFStringRef;
|
||||
}
|
||||
@@ -16,6 +16,7 @@ pub mod bundle;
|
||||
pub mod data;
|
||||
pub mod date;
|
||||
pub mod dictionary;
|
||||
pub mod error;
|
||||
pub mod number;
|
||||
pub mod runloop;
|
||||
pub mod set;
|
||||
|
||||
@@ -12,7 +12,7 @@ use libc::c_void;
|
||||
use base::{CFAllocatorRef, CFTypeID};
|
||||
|
||||
#[repr(C)]
|
||||
struct __CFBoolean(c_void);
|
||||
pub struct __CFBoolean(c_void);
|
||||
|
||||
pub type CFBooleanRef = *const __CFBoolean;
|
||||
|
||||
@@ -38,7 +38,7 @@ pub static kCFNumberFloat64Type: CFNumberType = 6;
|
||||
// static kCFNumberMaxType: CFNumberType = 16;
|
||||
|
||||
#[repr(C)]
|
||||
struct __CFNumber;
|
||||
pub struct __CFNumber;
|
||||
|
||||
pub type CFNumberRef = *const __CFNumber;
|
||||
|
||||
|
||||
@@ -15,17 +15,17 @@ use date::{CFAbsoluteTime, CFTimeInterval};
|
||||
use string::CFStringRef;
|
||||
|
||||
#[repr(C)]
|
||||
struct __CFRunLoop(c_void);
|
||||
pub struct __CFRunLoop(c_void);
|
||||
|
||||
pub type CFRunLoopRef = *const __CFRunLoop;
|
||||
|
||||
#[repr(C)]
|
||||
struct __CFRunLoopSource(c_void);
|
||||
pub struct __CFRunLoopSource(c_void);
|
||||
|
||||
pub type CFRunLoopSourceRef = *const __CFRunLoopSource;
|
||||
|
||||
#[repr(C)]
|
||||
struct __CFRunLoopObserver(c_void);
|
||||
pub struct __CFRunLoopObserver(c_void);
|
||||
|
||||
pub type CFRunLoopObserverRef = *const __CFRunLoopObserver;
|
||||
|
||||
@@ -97,7 +97,7 @@ pub struct CFRunLoopTimerContext {
|
||||
pub type CFRunLoopTimerCallBack = extern "C" fn (timer: CFRunLoopTimerRef, info: *mut c_void);
|
||||
|
||||
#[repr(C)]
|
||||
struct __CFRunLoopTimer;
|
||||
pub struct __CFRunLoopTimer;
|
||||
|
||||
pub type CFRunLoopTimerRef = *const __CFRunLoopTimer;
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ pub struct CFSetCallBacks {
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
struct __CFSet(c_void);
|
||||
pub struct __CFSet(c_void);
|
||||
|
||||
pub type CFSetRef = *const __CFSet;
|
||||
|
||||
|
||||
@@ -188,7 +188,7 @@ pub type CFStringEncodings = CFIndex;
|
||||
//static kCFStringEncodingShiftJIS_X0213_00: CFStringEncoding = 0x0628; /* Deprecated */
|
||||
|
||||
#[repr(C)]
|
||||
struct __CFString(c_void);
|
||||
pub struct __CFString(c_void);
|
||||
|
||||
pub type CFStringRef = *const __CFString;
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ use base::{CFOptionFlags, CFIndex, CFAllocatorRef, Boolean, CFTypeID};
|
||||
use string::CFStringRef;
|
||||
|
||||
#[repr(C)]
|
||||
struct __CFURL(c_void);
|
||||
pub struct __CFURL(c_void);
|
||||
|
||||
pub type CFURLRef = *const __CFURL;
|
||||
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
// Copyright 2016 The Servo Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
//! Core Foundation errors.
|
||||
|
||||
use core_foundation_sys::error::*;
|
||||
use core_foundation_sys::base::CFRelease;
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
|
||||
use base::{CFIndex, TCFType};
|
||||
use string::CFString;
|
||||
|
||||
/// An error value.
|
||||
pub struct CFError(CFErrorRef);
|
||||
|
||||
impl Drop for CFError {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
CFRelease(self.as_CFTypeRef())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl_TCFType!(CFError, CFErrorRef, CFErrorGetTypeID);
|
||||
|
||||
impl fmt::Debug for CFError {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt.debug_struct("CFError")
|
||||
.field("domain", &self.domain())
|
||||
.field("code", &self.code())
|
||||
.field("description", &self.description())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for CFError {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(fmt, "{}", self.description())
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for CFError {
|
||||
fn description(&self) -> &str {
|
||||
"a Core Foundation error"
|
||||
}
|
||||
}
|
||||
|
||||
impl CFError {
|
||||
/// Returns a string identifying the domain with which this error is
|
||||
/// associated.
|
||||
pub fn domain(&self) -> CFString {
|
||||
unsafe {
|
||||
let s = CFErrorGetDomain(self.0);
|
||||
CFString::wrap_under_get_rule(s)
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the code identifying this type of error.
|
||||
pub fn code(&self) -> CFIndex {
|
||||
unsafe { CFErrorGetCode(self.0) }
|
||||
}
|
||||
|
||||
/// Returns a human-presentable description of the error.
|
||||
pub fn description(&self) -> CFString {
|
||||
unsafe {
|
||||
let s = CFErrorCopyDescription(self.0);
|
||||
CFString::wrap_under_create_rule(s)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,6 +54,7 @@ pub mod boolean;
|
||||
pub mod data;
|
||||
pub use core_foundation_sys::date; // back compat
|
||||
pub mod dictionary;
|
||||
pub mod error;
|
||||
pub mod number;
|
||||
pub mod set;
|
||||
pub mod string;
|
||||
|
||||
Reference in New Issue
Block a user