Skip to main content

luaur_common/methods/
variant_fn_copy.rs

1use crate::records::variant::Variant1;
2
3impl<T0> Variant1<T0> {
4    /// Port of `Variant::fnCopy<T>`.
5    /// In the C++ implementation, this is used as a type-erased function pointer to perform
6    /// a placement-new copy of a specific type `T` from `src` to `dst`.
7    ///
8    /// # Safety
9    ///
10    /// This function is unsafe because it performs raw pointer dereferencing and writes to
11    /// uninitialized memory.
12    /// - `dst` must be valid for writes and properly aligned for `T`.
13    /// - `src` must be valid for reads, properly aligned for `T`, and contain a valid instance of `T`.
14    pub unsafe fn variant_fn_copy<T>(dst: *mut core::ffi::c_void, src: *const core::ffi::c_void)
15    where
16        T: Clone,
17    {
18        let src_val = &*(src as *const T);
19        let dst_ptr = dst as *mut T;
20        core::ptr::write(dst_ptr, src_val.clone());
21    }
22}