pub struct HotFn<A, M, F>where
F: HotFunction<A, M>,{ /* private fields */ }Expand description
A hot-reloadable function.
To call this function, use the HotFn::call method. This will automatically use the latest
version of the function from the JumpTable.
Implementations§
Source§impl<A, M, F: HotFunction<A, M>> HotFn<A, M, F>
impl<A, M, F: HotFunction<A, M>> HotFn<A, M, F>
Sourcepub const fn current(f: F) -> HotFn<A, M, F>
pub const fn current(f: F) -> HotFn<A, M, F>
Create a new HotFn instance with the current function.
Whenever you call HotFn::call, it will use the current function from the JumpTable.
Sourcepub fn call(&mut self, args: A) -> F::Return
pub fn call(&mut self, args: A) -> F::Return
Call the function with the given arguments.
This will unwrap the HotFnPanic panic, propagating up to the next HotFn::call.
If you want to handle the panic yourself, use HotFn::try_call.
Sourcepub fn ptr_address(&self) -> HotFnPtr
pub fn ptr_address(&self) -> HotFnPtr
Get the address of the function in memory which might be different than the original.
This is useful for implementing a memoization strategy to safely preserve state across hot-patches. If the ptr_address of a function did not change between patches, then the state that exists “above” the function is still valid.
Note that Subsecond does not track this state over time, so it’s up to the runtime integration to track this state and diff it.
Sourcepub fn try_call(&mut self, args: A) -> Result<F::Return, HotFnPanic>
pub fn try_call(&mut self, args: A) -> Result<F::Return, HotFnPanic>
Attempt to call the function with the given arguments.
If this function is stale and can’t be updated in place (ie, changes occurred above this call),
then this function will emit an HotFnPanic which can be unwrapped and handled by next call
instance.
Sourcepub unsafe fn try_call_with_ptr(
&mut self,
ptr: HotFnPtr,
args: A,
) -> Result<F::Return, HotFnPanic>
pub unsafe fn try_call_with_ptr( &mut self, ptr: HotFnPtr, args: A, ) -> Result<F::Return, HotFnPanic>
Attempt to call the function with the given arguments, using the given HotFnPtr.
You can get a HotFnPtr from Self::ptr_address.
If this function is stale and can’t be updated in place (ie, changes occurred above this call),
then this function will emit an HotFnPanic which can be unwrapped and handled by next call
instance.
§Safety
The HotFnPtr must be to a function whose arguments layouts haven’t changed.