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]

[src]

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

Methods from Deref<Target = Detour>

[src]

Enables or disables the detour.

[src]

Enables the detour.

[src]

Disables the detour.

[src]

Returns whether the detour is enabled or not.

[src]

Returns a reference to the generated trampoline.

Trait Implementations

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

[src]

Formats the value using the given formatter. Read more

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

The resulting type after dereferencing.

[src]

Dereferences the value.

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

[src]

Mutably dereferences the value.

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

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