rust_macios/core_foundation/
macros.rs1#[macro_export]
2macro_rules! declare_CFType {
3 (
4 $(#[$doc:meta])*
5 $ty:ident, $raw:ident
6 ) => {
7 $(#[$doc])*
8 pub struct $ty($raw);
9
10 impl Drop for $ty {
11 #[allow(trivial_casts)]
12 fn drop(&mut self) {
13 unsafe {
14 use $crate::core_foundation::CFTypeObject;
15 $crate::core_foundation::CFType::release(self.get_internal_object() as $crate::core_foundation::CFTypeRef) }
16 }
17 }
18
19 impl $crate::core_foundation::CFTypeObject for $ty {
20 type Ref = $raw;
21 #[allow(trivial_casts)]
22 fn get_internal_object(&self) -> Self::Ref {
23 self.0
24 }
25
26 fn create_with_ref(obj: Self::Ref) -> Self {
27 Self(obj)
28 }
29 }
30 }
31}