[][src]Struct hotpatch::Patchable

pub struct Patchable<Args, Ret> { /* fields omitted */ }

Created by #[patchable]. A functor capable of overwriting its own function.

Implementations

impl<Args: 'static, Ret: 'static> Patchable<Args, Ret>[src]

pub fn hotpatch_lib(&self, lib_name: &str) -> Result<(), Box<dyn Error>>[src]

Hotpatch this functor with functionality defined in lib_name. Will search a shared object cdylib file for #[patch] exports, finding the definition that matches module path and signature.

Example

#[patchable]
fn foo() {}

fn main() -> Result<(), Box<dyn std::error::Error>> {
  foo(); // does something
  foo.hotpatch_lib("libtest.so")?;
  foo(); // does something else
  Ok(())
}

pub fn try_hotpatch_lib(&self, lib_name: &str) -> Result<(), Box<dyn Error>>[src]

pub unsafe fn force_hotpatch_lib(
    &self,
    lib_name: &str
) -> Result<(), Box<dyn Error>>
[src]

Like hotpatch_lib but uses unsafe features to completly bypass the RwLock. Can be used to patch the current function or parent functions. Use with caution.

pub fn restore_default(&self) -> Result<(), Box<dyn Error>>[src]

Hotpatch this functor back to its original definition.

Example

#[patchable]
fn foo() {}

fn main() -> Result<(), Box<dyn std::error::Error>> {
  foo(); // does A
  foo.hotpatch_lib("libtest.so")?;
  foo(); // does B
  foo.restore_default();
  foo(); // does A again
  Ok(())
}

pub fn try_restore_default(&self) -> Result<(), Box<dyn Error>>[src]

pub unsafe fn force_restore_default(&self) -> Result<(), Box<dyn Error>>[src]

Like restore_default but uses unsafe features to completly bypass the RwLock. Can be used to patch the current function or parent functions. Use with caution.

impl<VaGen: 'static, Ret: 'static> Patchable<VaGen, Ret>[src]

pub fn hotpatch_fn<F: Send + Sync + 'static>(
    &self,
    ptr: F
) -> Result<(), Box<dyn Error>> where
    F: Fn(VaGen) -> Ret, 
[src]

Hotpatch this functor with functionality defined in ptr. ptr can be a function pointer or move closure with the same type signature as the functor's function.

Example

#[patchable]
fn foo(_: i32, _: i32, _: i32) {}

fn bar(_: i32, _: i32, _: i32) {}
 
fn main() -> Result<(), Box<dyn std::error::Error>> {
  foo.hotpatch_fn(bar)?;
  foo.hotpatch_fn(move |a, b, c| println!("{} {} {}", a, b, c))?;
  Ok(())
}

VaArgs Note

Implementation is defined with the variadic_generics crate. This means a macro is used to define a finite but large number of templated inputs. If using functions with large numbers of inputs and hotpatch_fn does not appear to be defined, compile hotpatch with the large-signatures feature to increase the number of supported arguements.

This is the only place where large_signatures is needed. Large signature functions are supported out of the box for hotpatch_lib and restore_default.

pub fn try_hotpatch_fn<F: Send + Sync + 'static>(
    &self,
    ptr: F
) -> Result<(), Box<dyn Error>> where
    F: Fn(VaGen) -> Ret, 
[src]

pub unsafe fn force_hotpatch_fn<F: Send + Sync + 'static>(
    &self,
    ptr: F
) -> Result<(), Box<dyn Error>> where
    F: Fn(VaGen) -> Ret, 
[src]

Like hotpatch_fn but uses unsafe features to completly bypass the RwLock. Can be used to patch the current function or parent functions. Use with caution.

Trait Implementations

impl<Args, Ret> Fn<Args> for Patchable<Args, Ret>[src]

impl<Args, Ret> FnMut<Args> for Patchable<Args, Ret>[src]

impl<Args, Ret> FnOnce<Args> for Patchable<Args, Ret>[src]

type Output = Ret

The returned type after the call operator is used.

Auto Trait Implementations

impl<Args, Ret> RefUnwindSafe for Patchable<Args, Ret>[src]

impl<Args, Ret> Send for Patchable<Args, Ret>[src]

impl<Args, Ret> Sync for Patchable<Args, Ret>[src]

impl<Args, Ret> Unpin for Patchable<Args, Ret>[src]

impl<Args, Ret> UnwindSafe for Patchable<Args, Ret>[src]

Blanket Implementations

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

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

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

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

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

impl<'a, F> Pattern<'a> for F where
    F: FnMut(char) -> bool
[src]

type Searcher = CharPredicateSearcher<'a, F>

🔬 This is a nightly-only experimental API. (pattern)

API not fully fleshed out and ready to be stabilized

Associated searcher for this pattern

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.

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.