pub struct GenericDetour<T: Function> { /* private fields */ }
Expand description

A type-safe 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)? };

assert_eq!(add5(5), 10);
assert_eq!(hook.call(5), 10);

unsafe { hook.enable()? };

assert_eq!(add5(5), 15);
assert_eq!(hook.call(5), 10);

unsafe { hook.disable()? };

assert_eq!(add5(5), 10);

Implementations

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

Enables the detour.

Disables the detour.

Returns whether the detour is enabled or not.

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.