Skip to main content

imping_hook/
function.rs

1//! The trait describing function signatures that can be hooked.
2
3mod sealed {
4    /// Prevents [`Function`](super::Function) from being implemented outside
5    /// this crate.
6    pub trait Sealed {}
7
8    impl<F: detour::Function> Sealed for F {}
9}
10
11/// A function pointer type that can be a [`Hook`](crate::Hook) target and
12/// detour.
13///
14/// Implemented for safe and `unsafe` function pointers with up to 14 arguments
15/// in every calling convention the platform has, such as `extern "C"`,
16/// `extern "system"`, and on x86 `extern "fastcall"` and `extern "thiscall"`.
17/// Signatures with borrows, such as `fn(&str)`, aren't supported. The trait is
18/// sealed.
19pub trait Function: sealed::Sealed + detour::Function {}
20
21impl<F: detour::Function> Function for F {}
22
23/// The original, unhooked function of a [`Hook`](crate::Hook), borrowed from
24/// it.
25///
26/// Its `call` method takes the hooked function's arguments and is `unsafe` when
27/// the signature is. It can't outlive the hook, so it never runs freed
28/// trampoline memory.
29pub use detour::Original;