endpoint_sec/event/event_clone.rs
1//! [`EventClone`]
2
3use std::ffi::OsStr;
4
5use endpoint_sec_sys::es_event_clone_t;
6
7use crate::File;
8
9/// Clone a file event.
10#[doc(alias = "es_event_clone_t")]
11pub struct EventClone<'a> {
12 /// Raw event
13 pub(crate) raw: &'a es_event_clone_t,
14}
15
16impl<'a> EventClone<'a> {
17 /// The file that will be cloned.
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 into which the `source` file will be cloned.
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 file to which `source` will be cloned.
32 #[inline(always)]
33 pub fn target_name(&self) -> &'a OsStr {
34 // Safety: 'a tied to self, object obtained through ES
35 unsafe { self.raw.target_name.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 EventClone<'_> {}
41// Safety: safe to share across threads: does not contain any interior mutability nor depend on current thread state
42unsafe impl Sync for EventClone<'_> {}
43
44impl_debug_eq_hash_with_functions!(EventClone<'a>; source, target_dir, target_name);