Struct detour::GenericDetour
source · [−]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
sourceimpl<T: Function> GenericDetour<T>
impl<T: Function> GenericDetour<T>
sourcepub unsafe fn new<D>(target: T, detour: D) -> Result<Self>where
T: HookableWith<D>,
D: Function,
pub unsafe fn new<D>(target: T, detour: D) -> Result<Self>where
T: HookableWith<D>,
D: Function,
Create a new hook given a target function and a compatible detour function.
sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Returns whether the detour is enabled or not.
Trait Implementations
sourceimpl<T: Debug + Function> Debug for GenericDetour<T>
impl<T: Debug + Function> Debug for GenericDetour<T>
impl<T: Function> Send for GenericDetour<T>
impl<T: Function> Sync for GenericDetour<T>
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
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more