retour/traits.rs
1//! Traits describing detours and applicable functions.
2//!
3//! Several of the traits in this module are automatically implemented and
4//! should generally not be implemented by users of this library.
5
6/// Trait representing a function that can be used as a target or detour for
7/// detouring.
8pub unsafe trait Function: Sized + Copy + Sync + 'static {
9 /// The argument types as a tuple.
10 type Arguments;
11
12 /// The return type.
13 type Output;
14
15 /// Constructs a `Function` from an untyped pointer.
16 unsafe fn from_ptr(ptr: *const ()) -> Self;
17
18 /// Returns an untyped pointer for this function.
19 fn to_ptr(&self) -> *const ();
20}
21
22/// Trait indicating that `Self` can be detoured by the given function `D`.
23pub unsafe trait HookableWith<D: Function>: Function {}
24
25unsafe impl<T: Function> HookableWith<T> for T {}
26
27impl_hookable! {
28 __arg_0: A, __arg_1: B, __arg_2: C, __arg_3: D, __arg_4: E, __arg_5: F, __arg_6: G,
29 __arg_7: H, __arg_8: I, __arg_9: J, __arg_10: K, __arg_11: L, __arg_12: M, __arg_13: N
30}