Struct detour::GenericDetour[][src]

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

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

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

pub unsafe fn new<D>(target: T, detour: D) -> Result<Self> where
    T: HookableWith<D>,
    D: Function
[src]

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

pub unsafe fn enable(&self) -> Result<()>[src]

Enables the detour.

pub unsafe fn disable(&self) -> Result<()>[src]

Disables the detour.

pub fn is_enabled(&self) -> bool[src]

Returns whether the detour is enabled or not.

Trait Implementations

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

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

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

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

Auto Trait Implementations

impl<T> !RefUnwindSafe for GenericDetour<T>

impl<T> Unpin for GenericDetour<T> where
    T: Unpin

impl<T> !UnwindSafe for GenericDetour<T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.