pub trait HotFunction<Args, Marker> {
type Return;
type Real;
// Required methods
fn call_it(&mut self, args: Args) -> Self::Return;
unsafe fn call_as_ptr(&mut self, _args: Args) -> Self::Return;
}Expand description
A trait that enables types to be hot-patched.
This trait is only implemented for FnMut types which naturally includes function pointers and closures that can be re-ran. FnOnce closures are currently not supported since the hot-patching system we use implies that the function can be called multiple times.
Required Associated Types§
Required Methods§
Sourcefn call_it(&mut self, args: Args) -> Self::Return
fn call_it(&mut self, args: Args) -> Self::Return
Call the HotFunction with the given arguments.
§Why
“rust-call” isn’t stable, so we wrap the underlying call with our own, giving it a stable vtable entry. This is more important than it seems since this function becomes “real” and can be hot-patched.
Sourceunsafe fn call_as_ptr(&mut self, _args: Args) -> Self::Return
unsafe fn call_as_ptr(&mut self, _args: Args) -> Self::Return
Call the HotFunction as if it were a function pointer.
§Safety
This is only safe if the underlying type is a function (function pointer or virtual/fat pointer). Using this will use the JumpTable to find the patched function and call it.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".