Struct hotpatch::Patchable [−][src]
Created by #[patchable]
. A functor capable of overwriting its
own function.
Implementations
impl<RealType: ?Sized + Send + Sync + 'static, VaGen, Ret> Patchable<RealType> where
RealType: Fn(VaGen) -> Ret,
[src]
RealType: Fn(VaGen) -> Ret,
pub fn hotpatch_fn<F>(&self, ptr: F) -> Result<(), Box<dyn Error>> where
F: Fn(VaGen) -> Ret,
[src]
F: Fn(VaGen) -> Ret,
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(()) }
Requires importing crate::HotpatchFn.
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.
pub fn try_hotpatch_fn<F>(&self, ptr: F) -> Result<(), Box<dyn Error>> where
F: Fn(VaGen) -> Ret,
[src]
F: Fn(VaGen) -> Ret,
Like hotpatch_fn
but uses
RwLock::try_write
.
pub unsafe fn force_hotpatch_fn<F>(&self, ptr: F) -> Result<(), Box<dyn Error>> where
F: Fn(VaGen) -> Ret,
[src]
F: Fn(VaGen) -> Ret,
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.
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(()) }
Requires importing crate::HotpatchLib.
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_lib
does not
appear to be defined, compile hotpatch
with the large-signatures
feature
to increase the number of supported arguements.
pub fn try_hotpatch_lib(&self, lib_name: &str) -> Result<(), Box<dyn Error>>
[src]
Like hotpatch_lib
but uses
RwLock::try_write
.
pub unsafe fn force_hotpatch_lib(
&self,
lib_name: &str
) -> Result<(), Box<dyn Error>>
[src]
&self,
lib_name: &str
) -> Result<(), Box<dyn Error>>
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.
impl<RealType: ?Sized + Send + Sync + 'static> Patchable<RealType>
[src]
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]
Like restore_default
but uses
RwLock::try_write
.
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.
Auto Trait Implementations
impl<RealType: ?Sized> RefUnwindSafe for Patchable<RealType>
[src]
impl<RealType: ?Sized> Send for Patchable<RealType>
[src]
impl<RealType: ?Sized> Sync for Patchable<RealType>
[src]
impl<RealType: ?Sized> Unpin for Patchable<RealType> where
RealType: Unpin,
[src]
RealType: Unpin,
impl<RealType: ?Sized> UnwindSafe for Patchable<RealType>
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
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]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,