Skip to main content

apple_log/
os_signpost_id.rs

1use crate::ffi;
2use crate::os_log::OSLog;
3
4/// Opaque signpost identifier.
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
6pub struct OSSignpostId(u64);
7
8/// Backwards-compatible alias for the pre-v0.5 signpost type.
9pub type SignpostId = OSSignpostId;
10
11impl OSSignpostId {
12    pub const NULL: Self = Self(ffi::signpost_id::NULL);
13    pub const INVALID: Self = Self(ffi::signpost_id::INVALID);
14    pub const EXCLUSIVE: Self = Self(ffi::signpost_id::EXCLUSIVE);
15
16    #[must_use]
17    pub fn generate(log: &OSLog) -> Self {
18        Self(unsafe { ffi::apple_log_os_signpost_id_generate(log.as_ptr()) })
19    }
20
21    #[must_use]
22    pub fn from_pointer<T>(log: &OSLog, pointer: *const T) -> Self {
23        Self(unsafe {
24            ffi::apple_log_os_signpost_id_make_with_pointer(log.as_ptr(), pointer.cast())
25        })
26    }
27
28    #[must_use]
29    pub const fn as_u64(self) -> u64 {
30        self.0
31    }
32
33    #[must_use]
34    pub const fn from_u64(raw: u64) -> Self {
35        Self(raw)
36    }
37
38    #[must_use]
39    pub const fn is_null(self) -> bool {
40        self.0 == Self::NULL.0
41    }
42
43    #[must_use]
44    pub const fn is_invalid(self) -> bool {
45        self.0 == Self::INVALID.0
46    }
47}