Skip to main content

endpoint_sec/event/
event_link.rs

1//! [`EventLink`]
2
3use std::ffi::OsStr;
4
5use endpoint_sec_sys::es_event_link_t;
6
7use crate::File;
8
9/// Link to a file event.
10#[doc(alias = "es_event_link_t")]
11pub struct EventLink<'a> {
12    /// Raw event
13    pub(crate) raw: &'a es_event_link_t,
14}
15
16impl<'a> EventLink<'a> {
17    /// The existing object to which a hard link will be created.
18    #[inline(always)]
19    pub fn source(&self) -> File<'a> {
20        // Safety: 'a tied to self, object obtained through ES
21        File::new(unsafe { self.raw.source() })
22    }
23
24    /// The directory in which the link will be created.
25    #[inline(always)]
26    pub fn target_dir(&self) -> File<'a> {
27        // Safety: 'a tied to self, object obtained through ES
28        File::new(unsafe { self.raw.target_dir() })
29    }
30
31    /// The name of the new object linked to the source file.
32    #[inline(always)]
33    pub fn target_filename(&self) -> &'a OsStr {
34        // Safety: 'a tied to self, object obtained through ES
35        unsafe { self.raw.target_filename.as_os_str() }
36    }
37}
38
39// Safety: safe to send across threads: does not contain any interior mutability nor depend on current thread state
40unsafe impl Send for EventLink<'_> {}
41// Safety: safe to share across threads: does not contain any interior mutability nor depend on current thread state
42unsafe impl Sync for EventLink<'_> {}
43
44impl_debug_eq_hash_with_functions!(EventLink<'a>; source, target_dir, target_filename);