Struct OpaqueFn

Source
#[repr(C)]
pub struct OpaqueFn<'a, A, R, B: Buffer> { /* private fields */ }
Expand description

A fixed-capacity inline function wrapper without allocation.

OpaqueFn<'a, A, R, N> can store any closure or function pointer that implements Fn(A) -> R and fits into a buffer of size N bytes.

§Note

Use call method to invoke the stored callable.

This is intended as a no-alloc alternative to Box<dyn Fn(A) -> R>.

Implementations§

Source§

impl<'a, A, R, B: Buffer> OpaqueFn<'a, A, R, B>

Source

pub fn new<F>(f: F) -> Self
where F: Fn(A) -> R + 'a,

Constructs a new OpaqueFn wrapping the given callable f.

§Panics

Panics if:

  • The size of F exceeds the buffer size N.
  • The alignment of F exceeds the alignment of the buffer.
Source

pub fn call<'call>(&self, a: A) -> R
where A: 'call,

Invokes the stored callable with argument a.

Trait Implementations§

Source§

impl<'a, A: Debug, R: Debug, B: Debug + Buffer> Debug for OpaqueFn<'a, A, R, B>

Source§

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

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

impl<A, R, B: Buffer> Drop for OpaqueFn<'_, A, R, B>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a, A, R, B> Freeze for OpaqueFn<'a, A, R, B>
where B: Freeze,

§

impl<'a, A, R, B> RefUnwindSafe for OpaqueFn<'a, A, R, B>
where B: RefUnwindSafe,

§

impl<'a, A, R, B> Send for OpaqueFn<'a, A, R, B>
where B: Send,

§

impl<'a, A, R, B> Sync for OpaqueFn<'a, A, R, B>
where B: Sync,

§

impl<'a, A, R, B> Unpin for OpaqueFn<'a, A, R, B>
where B: Unpin,

§

impl<'a, A, R, B> UnwindSafe for OpaqueFn<'a, A, R, B>
where B: 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.