HotFn

Struct HotFn 

Source
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>

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

§

impl<A, M, F> Freeze for HotFn<A, M, F>
where F: Freeze,

§

impl<A, M, F> RefUnwindSafe for HotFn<A, M, F>

§

impl<A, M, F> Send for HotFn<A, M, F>
where F: Send, A: Send, M: Send,

§

impl<A, M, F> Sync for HotFn<A, M, F>
where F: Sync, A: Sync, M: Sync,

§

impl<A, M, F> Unpin for HotFn<A, M, F>
where F: Unpin, A: Unpin, M: Unpin,

§

impl<A, M, F> UnwindSafe for HotFn<A, M, F>
where F: UnwindSafe, A: UnwindSafe, M: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.