BareFnMutAny

Struct BareFnMutAny 

Source
pub struct BareFnMutAny<B: FnPtr, S: ?Sized, A: JitAlloc = GlobalJitAlloc> { /* private fields */ }
Expand description

Wrapper around a FnMut 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 BareFnMut and BareFnMutSync 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 the bare_hrtb macro 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 the unstable feature, this is limited to dyn Any and combinations of Send and Sync marker types.
  • A: The JitAlloc implementation used to allocate and free executable memory.

Implementations§

Source§

impl<B: FnPtr, S: ?Sized> BareFnMutAny<B, S, GlobalJitAlloc>

Source

pub fn new<F>(fun: F) -> Self
where F: ToBoxedDyn<S>, (B::CC, F): FnMutThunk<B>,

Available on crate feature 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.

Source

pub fn with_cc<CC, F>(cconv: CC, fun: F) -> Self
where F: ToBoxedDyn<S>, (CC, F): FnMutThunk<B>,

Available on crate feature 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.

Source

pub fn with_thunk<T>(thunk: T) -> Self
where T: FnMutThunk<B> + ToBoxedDyn<S>,

Available on crate feature global_jit_alloc only.

Create a BareFnMutAny directly from a FnMutThunk.

The W^X memory required is allocated using the global JIT allocator.

Source§

impl<B: FnPtr, S: ?Sized, A: JitAlloc> BareFnMutAny<B, S, A>

Source

pub fn bare(&self) -> B

Return a bare function pointer that invokes the underlying closure.

§Safety

While this method is safe, the returned function pointer is not. In particular, it must not be called when:

  • The lifetime of self has expired, or self has been dropped.

  • The mutable borrow induced by a previous call is still active (e.g. through recursion) or concurrent (has no happens-before relationship) with the current one.

  • The closure is not Send, if calling from a different thread than the current one.

Source

pub fn leak(self) -> B
where 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 mutable borrow induced by a previous call is still active (e.g. through recursion) or concurrent (has no happens-before relationship) with the current one.

  • The closure is not Send, if calling from a different thread than the current one.

Source

pub fn into_untyped(self) -> UntypedBareFnMut<S, A>

Erase the signature type from this BareFnMutAny

The returned value also exposes the bare and leak functions. However, they now return untyped pointers.

Source

pub fn upcast<U: ?Sized>(self) -> BareFnMutAny<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>.

Source

pub fn try_with_cc_in<CC, F>( cconv: CC, fun: F, jit_alloc: A, ) -> Result<Self, JitAllocError>
where F: ToBoxedDyn<S>, (CC, F): FnMutThunk<B>,

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.

Source

pub fn with_cc_in<CC, F>(cconv: CC, fun: F, jit_alloc: A) -> Self
where F: ToBoxedDyn<S>, (CC, F): FnMutThunk<B>,

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

Source

pub fn new_in<F>(fun: F, jit_alloc: A) -> Self
where F: ToBoxedDyn<S>, (B::CC, F): FnMutThunk<B>,

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

Source

pub fn try_with_thunk_in<T>( thunk: T, jit_alloc: A, ) -> Result<Self, JitAllocError>
where T: FnMutThunk<B> + ToBoxedDyn<S>,

Create a BareFnMutAny directly from a FnMutThunk.

Uses jit_alloc to allocate the W^X memory used to create the thunk.

Source

pub fn with_thunk_in<T>(thunk: T, jit_alloc: A) -> Self
where T: FnMutThunk<B> + ToBoxedDyn<S>,

Create a BareFnMutAny directly from a FnMutThunk.

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> BareFnMutAny<B, S, GlobalJitAlloc>

Source

pub fn new_rust<F>(fun: F) -> Self
where F: ToBoxedDyn<S>, (Rust, F): FnMutThunk<B>,

Available on crate feature 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.

Source

pub fn new_c<F>(fun: F) -> Self
where F: ToBoxedDyn<S>, (C, F): FnMutThunk<B>,

Available on crate feature 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.

Source

pub fn new_system<F>(fun: F) -> Self
where F: ToBoxedDyn<S>, (System, F): FnMutThunk<B>,

Available on crate feature 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.

Source

pub fn new_efiabi<F>(fun: F) -> Self
where F: ToBoxedDyn<S>, (Efiapi, F): FnMutThunk<B>,

Available on crate feature 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.

Source

pub fn new_sysv64<F>(fun: F) -> Self
where F: ToBoxedDyn<S>, (Sysv64, F): FnMutThunk<B>,

Available on crate feature 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.

Source

pub fn new_aapcs<F>(fun: F) -> Self
where F: ToBoxedDyn<S>, (Aapcs, F): FnMutThunk<B>,

Available on crate feature 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.

Source

pub fn new_fastcall<F>(fun: F) -> Self
where F: ToBoxedDyn<S>, (Fastcall, F): FnMutThunk<B>,

Available on crate feature 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.

Source

pub fn new_stdcall<F>(fun: F) -> Self
where F: ToBoxedDyn<S>, (Stdcall, F): FnMutThunk<B>,

Available on crate feature 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.

Source

pub fn new_cdecl<F>(fun: F) -> Self
where F: ToBoxedDyn<S>, (Cdecl, F): FnMutThunk<B>,

Available on crate feature 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.

Source

pub fn new_thiscall<F>(fun: F) -> Self
where F: ToBoxedDyn<S>, (Thiscall, F): FnMutThunk<B>,

Available on crate feature 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.

Source

pub fn new_win64<F>(fun: F) -> Self
where F: ToBoxedDyn<S>, (Win64, F): FnMutThunk<B>,

Available on crate feature 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.

Source

pub fn new_variadic<F>(fun: F) -> Self
where F: ToBoxedDyn<S>, (Variadic, F): FnMutThunk<B>,

Available on crate feature 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> BareFnMutAny<B, S, A>

Source

pub fn new_rust_in<F>(fun: F, jit_alloc: A) -> Self
where F: ToBoxedDyn<S>, (Rust, F): FnMutThunk<B>,

Create a bare function thunk using the Rust calling convention for fun.

The W^X memory required is allocated using the provided JIT allocator.

Source

pub fn new_c_in<F>(fun: F, jit_alloc: A) -> Self
where F: ToBoxedDyn<S>, (C, F): FnMutThunk<B>,

Create a bare function thunk using the C calling convention for fun.

The W^X memory required is allocated using the provided JIT allocator.

Source

pub fn new_system_in<F>(fun: F, jit_alloc: A) -> Self
where F: ToBoxedDyn<S>, (System, F): FnMutThunk<B>,

Create a bare function thunk using the system calling convention for fun.

The W^X memory required is allocated using the provided JIT allocator.

Source

pub fn new_efiabi_in<F>(fun: F, jit_alloc: A) -> Self
where F: ToBoxedDyn<S>, (Efiapi, F): FnMutThunk<B>,

Create a bare function thunk using the efiapi calling convention for fun.

The W^X memory required is allocated using the provided JIT allocator.

Source

pub fn new_sysv64_in<F>(fun: F, jit_alloc: A) -> Self
where F: ToBoxedDyn<S>, (Sysv64, F): FnMutThunk<B>,

Available on 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 provided JIT allocator.

Source

pub fn new_aapcs_in<F>(fun: F, jit_alloc: A) -> Self
where F: ToBoxedDyn<S>, (Aapcs, F): FnMutThunk<B>,

Available on ARM only.

Create a bare function thunk using the aapcs calling convention for fun.

The W^X memory required is allocated using the provided JIT allocator.

Source

pub fn new_fastcall_in<F>(fun: F, jit_alloc: A) -> Self
where F: ToBoxedDyn<S>, (Fastcall, F): FnMutThunk<B>,

Available on 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 provided JIT allocator.

Source

pub fn new_stdcall_in<F>(fun: F, jit_alloc: A) -> Self
where F: ToBoxedDyn<S>, (Stdcall, F): FnMutThunk<B>,

Available on 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 provided JIT allocator.

Source

pub fn new_cdecl_in<F>(fun: F, jit_alloc: A) -> Self
where F: ToBoxedDyn<S>, (Cdecl, F): FnMutThunk<B>,

Available on 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 provided JIT allocator.

Source

pub fn new_thiscall_in<F>(fun: F, jit_alloc: A) -> Self
where F: ToBoxedDyn<S>, (Thiscall, F): FnMutThunk<B>,

Available on 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 provided JIT allocator.

Source

pub fn new_win64_in<F>(fun: F, jit_alloc: A) -> Self
where F: ToBoxedDyn<S>, (Win64, F): FnMutThunk<B>,

Available on 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 provided JIT allocator.

Source

pub fn new_variadic_in<F>(fun: F, jit_alloc: A) -> Self
where F: ToBoxedDyn<S>, (Variadic, F): FnMutThunk<B>,

Available on 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 provided JIT allocator.

Trait Implementations§

Source§

impl<B: FnPtr, S: ?Sized, U: ?Sized, A: JitAlloc> From<BareFnMutAny<B, S, A>> for UntypedBareFnMut<U, A>
where PhantomData<S>: ToBoxedDyn<U>,

Source§

fn from(value: BareFnMutAny<B, S, A>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<B, S, A> Freeze for BareFnMutAny<B, S, A>
where A: Freeze, S: ?Sized,

§

impl<B, S, A> RefUnwindSafe for BareFnMutAny<B, S, A>

§

impl<B, S, A> Send for BareFnMutAny<B, S, A>
where S: Send + ?Sized, A: Send,

§

impl<B, S, A> Sync for BareFnMutAny<B, S, A>
where S: Send + ?Sized,

§

impl<B, S, A> Unpin for BareFnMutAny<B, S, A>
where B: Unpin, A: Unpin, S: ?Sized,

§

impl<B, S, A> UnwindSafe for BareFnMutAny<B, S, A>

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<'a, T> ToBoxedDyn<dyn Any + 'a> for T
where T: 'a,

Source§

fn to_boxed_unsize(value: T) -> Box<dyn Any + 'a>

Constructs a Box<T> from Self, coercing into the unsized type.
Source§

impl<'a, T> ToBoxedDyn<dyn Send + 'a> for T
where T: Send + 'a,

Source§

fn to_boxed_unsize(value: T) -> Box<dyn Send + 'a>

Constructs a Box<T> from Self, coercing into the unsized type.
Source§

impl<'a, T> ToBoxedDyn<dyn Send + Sync + 'a> for T
where T: Send + Sync + 'a,

Source§

fn to_boxed_unsize(value: T) -> Box<dyn Send + Sync + 'a>

Constructs a Box<T> from Self, coercing into the unsized type.
Source§

impl<'a, T> ToBoxedDyn<dyn Sync + 'a> for T
where T: Sync + 'a,

Source§

fn to_boxed_unsize(value: T) -> Box<dyn Sync + 'a>

Constructs a Box<T> from Self, coercing into the unsized type.
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.
Source§

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