Struct detour::GenericDetour
[−]
[src]
pub struct GenericDetour<T: Function> { /* fields omitted */ }
A type-safe wrapper around Detour.
Due to being generated by a macro, the GenericDetour::call
method is not
exposed in the documentation.
It accepts the same arguments as T
, and shares its result type:
/// Calls the original function regardless of whether it's hooked or not
fn call(&self, T::Arguments) -> T::Output
Example
use detour::GenericDetour; fn add5(val: i32) -> i32 { val + 5 } fn add10(val: i32) -> i32 { val + 10 } let mut hook = unsafe { GenericDetour::<fn(i32) -> i32>::new(add5, add10).unwrap() }; assert_eq!(add5(5), 10); assert_eq!(hook.call(5), 10); unsafe { hook.enable().unwrap() }; assert_eq!(add5(5), 15); assert_eq!(hook.call(5), 10); unsafe { hook.disable().unwrap() }; assert_eq!(add5(5), 10);
Methods
impl<T: Function> GenericDetour<T>
[src]
pub unsafe fn new<D>(target: T, detour: D) -> Result<Self, Error> where
T: HookableWith<D>,
D: Function,
[src]
T: HookableWith<D>,
D: Function,
Create a new hook given a target function and a compatible detour function.
Methods from Deref<Target = Detour>
pub unsafe fn toggle(&mut self, enabled: bool) -> Result<(), Error>
[src]
Enables or disables the detour.
pub unsafe fn enable(&mut self) -> Result<(), Error>
[src]
Enables the detour.
pub unsafe fn disable(&mut self) -> Result<(), Error>
[src]
Disables the detour.
pub fn is_enabled(&self) -> bool
[src]
Returns whether the detour is enabled or not.
pub fn trampoline(&self) -> &()
[src]
Returns a reference to the generated trampoline.
Trait Implementations
impl<T: Debug + Function> Debug for GenericDetour<T>
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl<T: Function> Deref for GenericDetour<T>
[src]
type Target = Detour
The resulting type after dereferencing.
fn deref(&self) -> &Self::Target
[src]
Dereferences the value.