pub struct InlineFn<'a, Sig: FnSig, const SIZE: usize = DEFAULT_INLINE_FN_SIZE, S = Local> { /* private fields */ }Expand description
An inline-stored, partially type-erased Fn closure with compile-time capacity SIZE.
Similar to C++ fit::inline_function, InlineFn stores the callable’s captured environment
directly inline in a fixed-size buffer of SIZE bytes without heap allocation. Attempting to
construct an InlineFn from a closure whose size exceeds SIZE or alignment exceeds 8 bytes
fails at compile time.
The Sig parameter specifies the function signature using standard Rust function pointer
syntax, such as fn() -> u64 or fn(u32, bool) -> i32.
The S parameter controls thread-safety bounds:
Implementations§
Source§impl<'a, Sig: FnSig, const SIZE: usize, S> InlineFn<'a, Sig, SIZE, S>
impl<'a, Sig: FnSig, const SIZE: usize, S> InlineFn<'a, Sig, SIZE, S>
Sourcepub fn new<F>(closure: F) -> Selfwhere
F: FnWithSig<Sig> + 'a,
S: ThreadSafety<F>,
pub fn new<F>(closure: F) -> Selfwhere
F: FnWithSig<Sig> + 'a,
S: ThreadSafety<F>,
Wraps closure inline, asserting at compile time that its size is <= SIZE and
alignment is <= 8.
Sourcepub fn resize<const NEW_SIZE: usize>(self) -> InlineFn<'a, Sig, NEW_SIZE, S>
pub fn resize<const NEW_SIZE: usize>(self) -> InlineFn<'a, Sig, NEW_SIZE, S>
Widens the inline storage capacity to NEW_SIZE bytes (NEW_SIZE >= SIZE).
Fails to compile if NEW_SIZE < SIZE.
Sourcepub fn into_local(self) -> InlineFn<'a, Sig, SIZE, Local>
pub fn into_local(self) -> InlineFn<'a, Sig, SIZE, Local>
Relaxes the thread-safety marker of this InlineFn to Local (!Send + !Sync).
Sourcepub fn into_fn_mut(self) -> InlineFnMut<'a, Sig, SIZE, S>
pub fn into_fn_mut(self) -> InlineFnMut<'a, Sig, SIZE, S>
Converts this shared InlineFn into a mutable InlineFnMut with the same capacity and
thread-safety bounds at zero cost.
Sourcepub fn into_fn_once(self) -> InlineFnOnce<'a, Sig, SIZE, S>
pub fn into_fn_once(self) -> InlineFnOnce<'a, Sig, SIZE, S>
Converts this shared InlineFn into a single-use InlineFnOnce with the same capacity
and thread-safety bounds at zero cost.