Struct detour::GenericDetour [] [src]

pub struct GenericDetour<T: Function> { /* fields omitted */ }

A type-safe wrapper around RawDetour.

Therefore documentation related to RawDetour affects this interface as well.

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::{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]

[src]

Create a new hook given a target function and a compatible detour function.

Trait Implementations

impl<T: Debug + Function> Debug for GenericDetour<T>
[src]

[src]

Formats the value using the given formatter.

impl<T: Function> Detour for GenericDetour<T>
[src]

[src]

Enables or disables the detour.

[src]

Returns whether the detour is enabled or not.

[src]

Returns a reference to the generated trampoline.

[src]

Enables the detour.

[src]

Disables the detour

impl<T: Function> Send for GenericDetour<T>
[src]

impl<T: Function> Sync for GenericDetour<T>
[src]