core_foundation/
mach_port.rs

1use crate::base::TCFType;
2use crate::runloop::CFRunLoopSource;
3use core_foundation_sys::base::kCFAllocatorDefault;
4pub use core_foundation_sys::mach_port::*;
5
6declare_TCFType! {
7    /// An immutable numeric value.
8    CFMachPort, CFMachPortRef
9}
10impl_TCFType!(CFMachPort, CFMachPortRef, CFMachPortGetTypeID);
11impl_CFTypeDescription!(CFMachPort);
12
13impl CFMachPort {
14    pub fn create_runloop_source(&self, order: CFIndex) -> Result<CFRunLoopSource, ()> {
15        unsafe {
16            let runloop_source_ref =
17                CFMachPortCreateRunLoopSource(kCFAllocatorDefault, self.0, order);
18            if runloop_source_ref.is_null() {
19                Err(())
20            } else {
21                Ok(CFRunLoopSource::wrap_under_create_rule(runloop_source_ref))
22            }
23        }
24    }
25}