Skip to content

Commit c2e5cce

Browse files
committed
Add TCFReference trait
1 parent 9db89e7 commit c2e5cce

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

core-foundation-sys/src/base.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,23 @@ pub struct CFAllocatorContext {
8080
pub preferredSize: CFAllocatorPreferredSizeCallBack
8181
}
8282

83+
/// Trait for all types which are Core Foundation reference types.
84+
pub unsafe trait TCFReference {
85+
fn as_void_ptr(&self) -> *const c_void;
86+
87+
fn from_void_ptr(ptr: *const c_void) -> Self;
88+
}
89+
90+
unsafe impl<T> TCFReference for *const T {
91+
fn as_void_ptr(&self) -> *const c_void {
92+
(*self) as *const c_void
93+
}
94+
95+
fn from_void_ptr(ptr: *const c_void) -> Self {
96+
ptr as *const T
97+
}
98+
}
99+
83100
extern {
84101
/*
85102
* CFBase.h

0 commit comments

Comments
 (0)