endpoint_sec/event/event_close.rs
1//! [`EventClose`]
2
3use endpoint_sec_sys::es_event_close_t;
4
5use crate::File;
6
7/// Close a file descriptor event.
8#[doc(alias = "es_event_close_t")]
9pub struct EventClose<'a> {
10 /// Raw event
11 pub(crate) raw: &'a es_event_close_t,
12 /// Message version
13 pub(crate) version: u32,
14}
15
16impl<'a> EventClose<'a> {
17 /// true if the target file being closed has been modified.
18 #[inline(always)]
19 pub fn modified(&self) -> bool {
20 self.raw.modified
21 }
22
23 /// The file that is being closed.
24 #[inline(always)]
25 pub fn target(&self) -> File<'a> {
26 // Safety: 'a tied to self, object obtained through ES
27 File::new(unsafe { self.raw.target() })
28 }
29
30 /// If `true`, at some point in the lifetime of the target file vnode it was mapped into a
31 /// process as writable.
32 #[cfg(feature = "macos_13_0_0")]
33 #[inline(always)]
34 pub fn was_mapped_writable(&self) -> Option<bool> {
35 if self.version < 6 {
36 return None;
37 }
38 // Safety: 'a tied to self, object obtained through ES, we checked the version first
39 Some(unsafe { self.raw.anon0.was_mapped_writable })
40 }
41}
42
43// Safety: safe to send across threads: does not contain any interior mutability nor depend on current thread state
44unsafe impl Send for EventClose<'_> {}
45// Safety: safe to share across threads: does not contain any interior mutability nor depend on current thread state
46unsafe impl Sync for EventClose<'_> {}
47
48impl_debug_eq_hash_with_functions!(
49 EventClose<'a> with version;
50 modified,
51 target,
52 #[cfg(feature = "macos_13_0_0")] was_mapped_writable,
53);