Files
core-foundation-rs/base.rs
T
Patrick Walton 4d402a7937 Add booleans and refactor to support existential types.
This allows dictionaries to contain values of multiple CFTypes, while remaining
type-safe.
2012-08-30 18:43:43 -07:00

73 lines
1.3 KiB
Rust

use libc::c_long;
pub type Boolean = u8;
pub type CFIndex = c_long;
struct __CFAllocator { private: () }
pub type CFAllocatorRef = *__CFAllocator;
struct __CFType { private: () }
pub type CFTypeRef = *__CFType;
struct CFType {
obj: CFTypeRef,
drop {
unsafe {
CFRelease(self.obj)
}
}
}
impl CFType : AbstractCFType {
pure fn as_type_ref(&self) -> CFTypeRef {
self.obj
}
}
trait AbstractCFType {
pure fn as_type_ref(&self) -> CFTypeRef;
}
trait CFTypeOps {
fn as_type(self) -> CFType;
fn show(&self);
}
impl<T:AbstractCFType> T : CFTypeOps {
// Consumes self.
fn as_type(self) -> CFType {
CFType { obj: self.as_type_ref() }
}
fn show(&self) {
CFShow(self.as_type_ref());
}
}
#[link_args="-framework CoreFoundation"]
#[nolink]
extern {
/*
* CFBase.h
*/
const kCFAllocatorDefault: CFAllocatorRef;
const kCFAllocatorSystemDefault: CFAllocatorRef;
const kCFAllocatorMalloc: CFAllocatorRef;
const kCFAllocatorMallocZone: CFAllocatorRef;
const kCFAllocatorNull: CFAllocatorRef;
const kCFAllocatorUseContext: CFAllocatorRef;
fn CFRetain(cf: CFTypeRef) -> CFTypeRef;
fn CFRelease(cf: CFTypeRef);
/*
* CFString.h
*/
fn CFShow(obj: CFTypeRef);
}