Trait r3_core::closure::IntoClosureConst
source · pub trait IntoClosureConst {
// Required method
fn into_closure_const(self) -> Closure;
}
Expand description
A trait for converting a value into a Closure
at compile time.
The conversion may involve compile-time heap allocation
(core::intrinsics::const_allocate
). It’s illegal to use this trait’s
method at runtime.
Examples
#![feature(const_trait_impl)]
use r3_core::closure::{Closure, IntoClosureConst};
// `impl FnOnce()` → `Closure`
const _: Closure = (|| {}).into_closure_const();
// `(&'static P0, impl FnOnce(&'static P0))` → `Closure`
const _: Closure = (&42, |_: &i32| {}).into_closure_const();
// `(usize, impl FnOnce(usize))` → `Closure`
const _: Closure = (42usize, |_: usize| {}).into_closure_const();
Required Methods§
sourcefn into_closure_const(self) -> Closure
fn into_closure_const(self) -> Closure
Perform conversion to Closure
, potentially using a compile-time
heap.
Implementations on Foreign Types§
source§impl<T: FnOnce(usize) + Copy + Send + 'static> IntoClosureConst for (usize, T)
impl<T: FnOnce(usize) + Copy + Send + 'static> IntoClosureConst for (usize, T)
Packs usize
directly in ClosureEnv
if T
is zero-sized.
Due to compiler restrictions, this optimization is currently impossible
to do in the generic constructor (Closure::from_fn_const
).
const fn into_closure_const(self) -> Closure
source§impl<T: FnOnce(&'static P0) + Copy + Send + 'static, P0: Sync + 'static> IntoClosureConst for (&'static P0, T)
impl<T: FnOnce(&'static P0) + Copy + Send + 'static, P0: Sync + 'static> IntoClosureConst for (&'static P0, T)
Packs &P0
directly in ClosureEnv
if T
is zero-sized.
Due to compiler restrictions, this optimization is currently impossible
to do in the generic constructor (Closure::from_fn_const
).
const fn into_closure_const(self) -> Closure
Implementors§
impl IntoClosureConst for Closure
impl<T: FnOnce() + Copy + Send + 'static> IntoClosureConst for T
Perform conversion using Closure::from_fn_const
.