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]
impl<T: Function> GenericDetour<T>
[src]pub unsafe fn new<D>(target: T, detour: D) -> Result<Self> where
T: HookableWith<D>,
D: Function,
[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 fn is_enabled(&self) -> bool
[src]
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]
impl<T: Debug + Function> Debug for GenericDetour<T>
[src]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,
T: Unpin,
impl<T> !UnwindSafe for GenericDetour<T>
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> Same<T> for T
impl<T> Same<T> for T
type Output = T
type Output = T
Should always be Self