pub struct BareFnOnceAny<B: FnPtr, S: ?Sized, A: JitAlloc = GlobalJitAlloc> { /* private fields */ }Expand description
Wrapper around a
FnOnce
closure which exposes a bare function thunk that can invoke it without
additional arguments.
§Note
This is a generic implementation which allows customizing the closure’s
type erased storage, which allows enforcing trait bounds like Send and Sync when
needed. However, this plays poorly with type inference. Consider using the
BareFnOnce
and
BareFnOnceSync
type aliases for the common cases of S = dyn Any + 'a (no thread safety constraints)
and
S = dyn Send + 'a
(minimum required to safely store/call the closure from other threads), respectively.
§Type parameters
B: The bare function pointer to expose the closure as. For higher-kinded bare function pointers, you will need to use thebare_hrtbmacro to define a wrapper type.S: The dynamically-sized type to use to type-erase the closure. Use this to enforce lifetime bounds and marker traits which the closure must satisfy, e.g.S = dyn Send + 'a. Without theunstablefeature, this is limited todyn Anyand combinations ofSendandSyncmarker types.A: TheJitAllocimplementation used to allocate and free executable memory.
Implementations§
Source§impl<B: FnPtr, S: ?Sized> BareFnOnceAny<B, S, GlobalJitAlloc>
impl<B: FnPtr, S: ?Sized> BareFnOnceAny<B, S, GlobalJitAlloc>
Sourcepub fn new<F>(fun: F) -> Self
Available on crate feature global_jit_alloc only.
pub fn new<F>(fun: F) -> Self
global_jit_alloc only.Wraps fun, producing a bare function of signature B.
This constructor is best used when the type of B is already known from an existing
type annotation. If you want to infer B from the closure arguments and a calling
convention, consider using
with_cc
or the new_* suffixed constructors instead.
The W^X memory required is allocated using the global JIT allocator.
Sourcepub fn with_cc<CC, F>(cconv: CC, fun: F) -> Self
Available on crate feature global_jit_alloc only.
pub fn with_cc<CC, F>(cconv: CC, fun: F) -> Self
global_jit_alloc only.Wraps fun, producing a bare function with calling convention cconv.
The W^X memory required is allocated using the global JIT allocator.
Sourcepub fn with_thunk<T>(thunk: T) -> Selfwhere
T: FnOnceThunk<B> + ToBoxedDyn<S>,
Available on crate feature global_jit_alloc only.
pub fn with_thunk<T>(thunk: T) -> Selfwhere
T: FnOnceThunk<B> + ToBoxedDyn<S>,
global_jit_alloc only.Create a
BareFnOnceAny
directly from a
FnOnceThunk.
The W^X memory required is allocated using the global JIT allocator.
Source§impl<B: FnPtr, S: ?Sized, A: JitAlloc> BareFnOnceAny<B, S, A>
impl<B: FnPtr, S: ?Sized, A: JitAlloc> BareFnOnceAny<B, S, A>
Sourcepub fn leak(self) -> Bwhere
Self: 'static,
pub fn leak(self) -> Bwhere
Self: 'static,
Leak the underlying closure, returning the unsafe bare function pointer that invokes it.
self must be 'static for this method to be called.
§Safety
While this method is safe, the returned function pointer is not. In particular, it must not be called when:
-
The function has been called before.
-
The closure is not
Send, if calling from a different thread than the current one.
Sourcepub fn into_untyped(self) -> UntypedBareFnOnce<S, A>
pub fn into_untyped(self) -> UntypedBareFnOnce<S, A>
Erase the signature type from this
BareFnOnceAny
The returned value also exposes the bare and leak functions.
However, they now return untyped pointers.
Sourcepub fn upcast<U: ?Sized>(self) -> BareFnOnceAny<B, U, A>where
PhantomData<S>: ToBoxedDyn<U>,
pub fn upcast<U: ?Sized>(self) -> BareFnOnceAny<B, U, A>where
PhantomData<S>: ToBoxedDyn<U>,
Weaken the bounds of the type-erased storage.
For example, a BareFnAny<B, dyn Send + Sync> may be upcast into a BareFnAny<B, dyn Send>.
Sourcepub fn try_with_cc_in<CC, F>(
cconv: CC,
fun: F,
jit_alloc: A,
) -> Result<Self, JitAllocError>
pub fn try_with_cc_in<CC, F>( cconv: CC, fun: F, jit_alloc: A, ) -> Result<Self, JitAllocError>
Wraps fun, producing a bare function with calling convention cconv.
Uses the provided JIT allocator to allocate the W^X memory used to create the thunk.
Sourcepub fn with_cc_in<CC, F>(cconv: CC, fun: F, jit_alloc: A) -> Self
pub fn with_cc_in<CC, F>(cconv: CC, fun: F, jit_alloc: A) -> Self
Wraps fun, producing a bare function with calling convention cconv.
Uses jit_alloc to allocate the W^X memory used to create the thunk.
§Panics
If the provided JIT allocator fails to allocate memory. For a non-panicking
version, see
try_with_cc_in
Sourcepub fn new_in<F>(fun: F, jit_alloc: A) -> Self
pub fn new_in<F>(fun: F, jit_alloc: A) -> Self
Wraps fun, producing a bare function with signature B.
Uses jit_alloc to allocate the W^X memory used to create the thunk.
This constructor is best used when the type of B is already known from an existing
type annotation. If you want to infer B from the closure arguments and a calling
convention, consider using
with_cc_in
instead.
§Panics
If the provided JIT allocator fails to allocate memory. For a non-panicking
version, see
try_with_cc_in
Sourcepub fn try_with_thunk_in<T>(
thunk: T,
jit_alloc: A,
) -> Result<Self, JitAllocError>where
T: FnOnceThunk<B> + ToBoxedDyn<S>,
pub fn try_with_thunk_in<T>(
thunk: T,
jit_alloc: A,
) -> Result<Self, JitAllocError>where
T: FnOnceThunk<B> + ToBoxedDyn<S>,
Create a
BareFnOnceAny
directly from a
FnOnceThunk.
Uses jit_alloc to allocate the W^X memory used to create the thunk.
Sourcepub fn with_thunk_in<T>(thunk: T, jit_alloc: A) -> Selfwhere
T: FnOnceThunk<B> + ToBoxedDyn<S>,
pub fn with_thunk_in<T>(thunk: T, jit_alloc: A) -> Selfwhere
T: FnOnceThunk<B> + ToBoxedDyn<S>,
Create a
BareFnOnceAny
directly from a
FnOnceThunk.
Uses jit_alloc to allocate the W^X memory used to create the thunk.
§Panics
If the provided JIT allocator fails to allocate memory. For a non-panicking
version, see Self::try_with_thunk_in.
Source§impl<B: FnPtr, S: ?Sized> BareFnOnceAny<B, S, GlobalJitAlloc>
impl<B: FnPtr, S: ?Sized> BareFnOnceAny<B, S, GlobalJitAlloc>
Sourcepub fn new_rust<F>(fun: F) -> Self
Available on crate feature global_jit_alloc only.
pub fn new_rust<F>(fun: F) -> Self
global_jit_alloc only.Create a bare function thunk using the
Rust
calling convention for fun.
The W^X memory required is allocated using the global JIT allocator.
Sourcepub fn new_c<F>(fun: F) -> Self
Available on crate feature global_jit_alloc only.
pub fn new_c<F>(fun: F) -> Self
global_jit_alloc only.Create a bare function thunk using the
C
calling convention for fun.
The W^X memory required is allocated using the global JIT allocator.
Sourcepub fn new_system<F>(fun: F) -> Self
Available on crate feature global_jit_alloc only.
pub fn new_system<F>(fun: F) -> Self
global_jit_alloc only.Create a bare function thunk using the
system
calling convention for fun.
The W^X memory required is allocated using the global JIT allocator.
Sourcepub fn new_efiabi<F>(fun: F) -> Self
Available on crate feature global_jit_alloc only.
pub fn new_efiabi<F>(fun: F) -> Self
global_jit_alloc only.Create a bare function thunk using the
efiapi
calling convention for fun.
The W^X memory required is allocated using the global JIT allocator.
Sourcepub fn new_sysv64<F>(fun: F) -> Self
Available on crate feature global_jit_alloc and (non-Windows and x86-64) only.
pub fn new_sysv64<F>(fun: F) -> Self
global_jit_alloc and (non-Windows and x86-64) only.Create a bare function thunk using the
sysv64
calling convention for fun.
The W^X memory required is allocated using the global JIT allocator.
Sourcepub fn new_aapcs<F>(fun: F) -> Self
Available on crate feature global_jit_alloc and (ARM) only.
pub fn new_aapcs<F>(fun: F) -> Self
global_jit_alloc and (ARM) only.Create a bare function thunk using the
aapcs
calling convention for fun.
The W^X memory required is allocated using the global JIT allocator.
Sourcepub fn new_fastcall<F>(fun: F) -> Self
Available on crate feature global_jit_alloc and (Windows and x86) only.
pub fn new_fastcall<F>(fun: F) -> Self
global_jit_alloc and (Windows and x86) only.Create a bare function thunk using the
fastcall
calling convention for fun.
The W^X memory required is allocated using the global JIT allocator.
Sourcepub fn new_stdcall<F>(fun: F) -> Self
Available on crate feature global_jit_alloc and (Windows and x86) only.
pub fn new_stdcall<F>(fun: F) -> Self
global_jit_alloc and (Windows and x86) only.Create a bare function thunk using the
stdcall
calling convention for fun.
The W^X memory required is allocated using the global JIT allocator.
Sourcepub fn new_cdecl<F>(fun: F) -> Self
Available on crate feature global_jit_alloc and (Windows and x86) only.
pub fn new_cdecl<F>(fun: F) -> Self
global_jit_alloc and (Windows and x86) only.Create a bare function thunk using the
cdecl
calling convention for fun.
The W^X memory required is allocated using the global JIT allocator.
Sourcepub fn new_thiscall<F>(fun: F) -> Self
Available on crate feature global_jit_alloc and (Windows and x86) only.
pub fn new_thiscall<F>(fun: F) -> Self
global_jit_alloc and (Windows and x86) only.Create a bare function thunk using the
thiscall
calling convention for fun.
The W^X memory required is allocated using the global JIT allocator.
Sourcepub fn new_win64<F>(fun: F) -> Self
Available on crate feature global_jit_alloc and (Windows and x86-64) only.
pub fn new_win64<F>(fun: F) -> Self
global_jit_alloc and (Windows and x86-64) only.Create a bare function thunk using the
win64
calling convention for fun.
The W^X memory required is allocated using the global JIT allocator.
Sourcepub fn new_variadic<F>(fun: F) -> Self
Available on crate feature global_jit_alloc and (crate features c_variadic) only.
pub fn new_variadic<F>(fun: F) -> Self
global_jit_alloc and (crate features c_variadic) only.Create a bare function thunk using the
C variadic
calling convention for fun.
The W^X memory required is allocated using the global JIT allocator.
Source§impl<B: FnPtr, S: ?Sized, A: JitAlloc> BareFnOnceAny<B, S, A>
impl<B: FnPtr, S: ?Sized, A: JitAlloc> BareFnOnceAny<B, S, A>
Sourcepub fn new_rust_in<F>(fun: F, jit_alloc: A) -> Self
pub fn new_rust_in<F>(fun: F, jit_alloc: A) -> Self
Create a bare function thunk using the
Rust
calling convention for fun.
The W^X memory required is allocated using the provided JIT allocator.
Sourcepub fn new_c_in<F>(fun: F, jit_alloc: A) -> Self
pub fn new_c_in<F>(fun: F, jit_alloc: A) -> Self
Create a bare function thunk using the
C
calling convention for fun.
The W^X memory required is allocated using the provided JIT allocator.
Sourcepub fn new_system_in<F>(fun: F, jit_alloc: A) -> Self
pub fn new_system_in<F>(fun: F, jit_alloc: A) -> Self
Create a bare function thunk using the
system
calling convention for fun.
The W^X memory required is allocated using the provided JIT allocator.
Sourcepub fn new_efiabi_in<F>(fun: F, jit_alloc: A) -> Self
pub fn new_efiabi_in<F>(fun: F, jit_alloc: A) -> Self
Create a bare function thunk using the
efiapi
calling convention for fun.
The W^X memory required is allocated using the provided JIT allocator.
Sourcepub fn new_sysv64_in<F>(fun: F, jit_alloc: A) -> Self
Available on non-Windows and x86-64 only.
pub fn new_sysv64_in<F>(fun: F, jit_alloc: A) -> Self
Create a bare function thunk using the
sysv64
calling convention for fun.
The W^X memory required is allocated using the provided JIT allocator.
Sourcepub fn new_aapcs_in<F>(fun: F, jit_alloc: A) -> Self
Available on ARM only.
pub fn new_aapcs_in<F>(fun: F, jit_alloc: A) -> Self
Create a bare function thunk using the
aapcs
calling convention for fun.
The W^X memory required is allocated using the provided JIT allocator.
Sourcepub fn new_fastcall_in<F>(fun: F, jit_alloc: A) -> Self
Available on Windows and x86 only.
pub fn new_fastcall_in<F>(fun: F, jit_alloc: A) -> Self
Create a bare function thunk using the
fastcall
calling convention for fun.
The W^X memory required is allocated using the provided JIT allocator.
Sourcepub fn new_stdcall_in<F>(fun: F, jit_alloc: A) -> Self
Available on Windows and x86 only.
pub fn new_stdcall_in<F>(fun: F, jit_alloc: A) -> Self
Create a bare function thunk using the
stdcall
calling convention for fun.
The W^X memory required is allocated using the provided JIT allocator.
Sourcepub fn new_cdecl_in<F>(fun: F, jit_alloc: A) -> Self
Available on Windows and x86 only.
pub fn new_cdecl_in<F>(fun: F, jit_alloc: A) -> Self
Create a bare function thunk using the
cdecl
calling convention for fun.
The W^X memory required is allocated using the provided JIT allocator.
Sourcepub fn new_thiscall_in<F>(fun: F, jit_alloc: A) -> Self
Available on Windows and x86 only.
pub fn new_thiscall_in<F>(fun: F, jit_alloc: A) -> Self
Create a bare function thunk using the
thiscall
calling convention for fun.
The W^X memory required is allocated using the provided JIT allocator.
Sourcepub fn new_win64_in<F>(fun: F, jit_alloc: A) -> Self
Available on Windows and x86-64 only.
pub fn new_win64_in<F>(fun: F, jit_alloc: A) -> Self
Create a bare function thunk using the
win64
calling convention for fun.
The W^X memory required is allocated using the provided JIT allocator.
Sourcepub fn new_variadic_in<F>(fun: F, jit_alloc: A) -> Self
Available on crate features c_variadic only.
pub fn new_variadic_in<F>(fun: F, jit_alloc: A) -> Self
c_variadic only.Create a bare function thunk using the
C variadic
calling convention for fun.
The W^X memory required is allocated using the provided JIT allocator.