Skip to main content

endpoint_sec/event/
event_lookup.rs

1//! [`EventLookup`]
2
3use std::ffi::OsStr;
4
5use endpoint_sec_sys::es_event_lookup_t;
6
7use crate::File;
8
9/// Lookup a file system object event.
10#[doc(alias = "es_event_lookup_t")]
11pub struct EventLookup<'a> {
12    /// Raw event
13    pub(crate) raw: &'a es_event_lookup_t,
14}
15
16impl<'a> EventLookup<'a> {
17    /// The current directory.
18    #[inline(always)]
19    pub fn source_dir(&self) -> File<'a> {
20        // Safety: 'a tied to self, object obtained through ES
21        File::new(unsafe { self.raw.source_dir() })
22    }
23
24    /// The path to lookup relative to the current directory.
25    #[inline(always)]
26    pub fn relative_target(&self) -> &'a OsStr {
27        // Safety: 'a tied to self, object obtained through ES
28        unsafe { self.raw.relative_target.as_os_str() }
29    }
30}
31
32// Safety: safe to send across threads: does not contain any interior mutability nor depend on current thread state
33unsafe impl Send for EventLookup<'_> {}
34// Safety: safe to share across threads: does not contain any interior mutability nor depend on current thread state
35unsafe impl Sync for EventLookup<'_> {}
36
37impl_debug_eq_hash_with_functions!(EventLookup<'a>; source_dir, relative_target);