Skip to main content

InlineFn

Struct InlineFn 

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

  • Local (default): !Send + !Sync, accepts any closure F: Fn(...) + 'a.
  • SendOnly: Send + !Sync, requires F: Send.
  • SendSync: Send + Sync, requires F: Send + Sync.

Implementations§

Source§

impl<'a, Sig: FnSig, const SIZE: usize, S> InlineFn<'a, Sig, SIZE, S>

Source

pub fn new<F>(closure: F) -> Self
where F: FnWithSig<Sig> + 'a, S: ThreadSafety<F>,

Wraps closure inline, asserting at compile time that its size is <= SIZE and alignment is <= 8.

Source

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.

Source

pub fn into_local(self) -> InlineFn<'a, Sig, SIZE, Local>

Relaxes the thread-safety marker of this InlineFn to Local (!Send + !Sync).

Source

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.

Source

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.

Source§

impl<'a, Sig: FnSig, const SIZE: usize> InlineFn<'a, Sig, SIZE, Local>

Source

pub fn new_local<F>(closure: F) -> Self
where F: FnWithSig<Sig> + 'a,

Creates a local (!Send + !Sync) InlineFn.

Source§

impl<'a, Sig: FnSig, const SIZE: usize> InlineFn<'a, Sig, SIZE, SendOnly>

Source

pub fn new_send<F>(closure: F) -> Self
where F: FnWithSig<Sig> + Send + 'a,

Creates a Send (!Sync) InlineFn.

Source§

impl<'a, Sig: FnSig, const SIZE: usize> InlineFn<'a, Sig, SIZE, SendSync>

Source

pub fn new_send_sync<F>(closure: F) -> Self
where F: FnWithSig<Sig> + Send + Sync + 'a,

Creates a Send + Sync InlineFn.

Source

pub fn into_send(self) -> InlineFn<'a, Sig, SIZE, SendOnly>

Relaxes the thread-safety marker from SendSync to SendOnly.

Source§

impl<'a, Ret, const SIZE: usize, S> InlineFn<'a, fn() -> Ret, SIZE, S>

Source

pub fn call(&self) -> Ret

Invokes the underlying closure with the provided arguments.

Source§

impl<'a, A1, Ret, const SIZE: usize, S> InlineFn<'a, fn(A1) -> Ret, SIZE, S>

Source

pub fn call(&self, a1: A1) -> Ret

Invokes the underlying closure with the provided arguments.

Source§

impl<'a, A1, A2, Ret, const SIZE: usize, S> InlineFn<'a, fn(A1, A2) -> Ret, SIZE, S>

Source

pub fn call(&self, a1: A1, a2: A2) -> Ret

Invokes the underlying closure with the provided arguments.

Source§

impl<'a, A1, A2, A3, Ret, const SIZE: usize, S> InlineFn<'a, fn(A1, A2, A3) -> Ret, SIZE, S>

Source

pub fn call(&self, a1: A1, a2: A2, a3: A3) -> Ret

Invokes the underlying closure with the provided arguments.

Source§

impl<'a, A1, A2, A3, A4, Ret, const SIZE: usize, S> InlineFn<'a, fn(A1, A2, A3, A4) -> Ret, SIZE, S>

Source

pub fn call(&self, a1: A1, a2: A2, a3: A3, a4: A4) -> Ret

Invokes the underlying closure with the provided arguments.

Source§

impl<'a, A1, A2, A3, A4, A5, Ret, const SIZE: usize, S> InlineFn<'a, fn(A1, A2, A3, A4, A5) -> Ret, SIZE, S>

Source

pub fn call(&self, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5) -> Ret

Invokes the underlying closure with the provided arguments.

Source§

impl<'a, A1, A2, A3, A4, A5, A6, Ret, const SIZE: usize, S> InlineFn<'a, fn(A1, A2, A3, A4, A5, A6) -> Ret, SIZE, S>

Source

pub fn call(&self, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6) -> Ret

Invokes the underlying closure with the provided arguments.

Source§

impl<'a, A1, A2, A3, A4, A5, A6, A7, Ret, const SIZE: usize, S> InlineFn<'a, fn(A1, A2, A3, A4, A5, A6, A7) -> Ret, SIZE, S>

Source

pub fn call( &self, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7, ) -> Ret

Invokes the underlying closure with the provided arguments.

Source§

impl<'a, A1, A2, A3, A4, A5, A6, A7, A8, Ret, const SIZE: usize, S> InlineFn<'a, fn(A1, A2, A3, A4, A5, A6, A7, A8) -> Ret, SIZE, S>

Source

pub fn call( &self, a1: A1, a2: A2, a3: A3, a4: A4, a5: A5, a6: A6, a7: A7, a8: A8, ) -> Ret

Invokes the underlying closure with the provided arguments.

Trait Implementations§

Source§

impl<'a, Sig: FnSig, const SIZE: usize, S> Debug for InlineFn<'a, Sig, SIZE, S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, Sig: FnSig, const SIZE: usize, S> From<InlineFn<'a, Sig, SIZE, S>> for InlineFnMut<'a, Sig, SIZE, S>

Source§

fn from(func: InlineFn<'a, Sig, SIZE, S>) -> Self

Converts to this type from the input type.
Source§

impl<'a, Sig: FnSig, const SIZE: usize, S> From<InlineFn<'a, Sig, SIZE, S>> for InlineFnOnce<'a, Sig, SIZE, S>

Source§

fn from(func: InlineFn<'a, Sig, SIZE, S>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'a, Sig, const SIZE: usize = DEFAULT_INLINE_FN_SIZE, S = Local> !Freeze for InlineFn<'a, Sig, SIZE, S>

§

impl<'a, Sig, const SIZE: usize = DEFAULT_INLINE_FN_SIZE, S = Local> !RefUnwindSafe for InlineFn<'a, Sig, SIZE, S>

§

impl<'a, Sig, const SIZE: usize, S> Send for InlineFn<'a, Sig, SIZE, S>
where S: Send,

§

impl<'a, Sig, const SIZE: usize, S> Sync for InlineFn<'a, Sig, SIZE, S>
where S: Sync,

§

impl<'a, Sig, const SIZE: usize, S> Unpin for InlineFn<'a, Sig, SIZE, S>
where <Sig as FnSig>::Trampoline: Unpin, S: Unpin,

§

impl<'a, Sig, const SIZE: usize, S> UnsafeUnpin for InlineFn<'a, Sig, SIZE, S>
where <Sig as FnSig>::Trampoline: UnsafeUnpin,

§

impl<'a, Sig, const SIZE: usize, S> UnwindSafe for InlineFn<'a, Sig, SIZE, S>
where <Sig as FnSig>::Trampoline: UnwindSafe, S: UnwindSafe,

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

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> ToMutPtr for T
where T: ?Sized,

Source§

type Target = T

The target type of the pointer.
Source§

fn to_mut_ptr(&self) -> *mut T

Casts the reference to a mutable raw pointer.
§

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

§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.