summaryrefslogtreecommitdiffstats
path: root/vendor/sysinfo/src/apple/macos/utils.rs
blob: ff870db553c8c082bd41bf6d7c48cc4e24353470 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Take a look at the license at the top of the repository in the LICENSE file.

use std::num::NonZeroU32;

type IoObject = NonZeroU32;

pub(crate) struct IOReleaser(IoObject);

impl IOReleaser {
    pub(crate) fn new(obj: u32) -> Option<Self> {
        IoObject::new(obj).map(Self)
    }

    pub(crate) unsafe fn new_unchecked(obj: u32) -> Self {
        // Chance at catching in-development mistakes
        debug_assert_ne!(obj, 0);
        Self(IoObject::new_unchecked(obj))
    }

    #[inline]
    pub(crate) fn inner(&self) -> u32 {
        self.0.get()
    }
}

impl Drop for IOReleaser {
    fn drop(&mut self) {
        unsafe { super::ffi::IOObjectRelease(self.0.get() as _) };
    }
}