Skip to main content

chaud_hot/func/
def.rs

1/// A trait that aggregates information about hot-reloadable functions.
2///
3/// This is implemented for macro-generated synthetic types. The `Self` type
4/// has little meaning.
5///
6/// # Safety
7///
8/// [`Self::Ptr`] must be a function pointer.
9#[expect(non_upper_case_globals, reason = "function-like usage")]
10pub unsafe trait Func {
11    /// The function pointer type corresponding to this function.
12    type Ptr: FnPtrLike;
13
14    /// A name describing this function.
15    ///
16    /// Only for human usage.
17    const NAME: &str;
18
19    /// The "actual" implementation of this function.
20    ///
21    /// This is the function as defind by the user.
22    const actual: Self::Ptr;
23}
24
25/// A trait implemented for types that might be function pointers.
26///
27/// This is primarily used to aggregate and enforce the bounds we care about.
28///
29/// Ideally we'd use [`core::marker::FnPtr`] (if something like it is ever
30/// stabilized).
31pub trait FnPtrLike: Copy + Send + Sync + 'static {}
32
33impl<F: Copy + Send + Sync + 'static> FnPtrLike for F {}