Trait itron_asp3::closure::IntoClosure [−][src]
pub trait IntoClosure {
fn into_closure(self) -> Closure;
}
This is supported on crate feature
unstable
only.Expand description
Conversion to Closure
.
Required methods
fn into_closure(self) -> Closure
fn into_closure(self) -> Closure
Convert self
to Closure
.
Implementations on Foreign Types
Trivial conversion.
Implementors
Example
use itron::closure::IntoClosure;
let (fp, data) = (|| dbg!()).into_closure();
unsafe { fp(data) };
let captured_value = 42u16;
let (fp, data) = (move || { assert_eq!(captured_value, 42); }).into_closure();
unsafe { fp(data) };
let captured_value = &"hello";
let (fp, data) = (move || { assert_eq!(*captured_value, "hello"); }).into_closure();
unsafe { fp(data) };
The source type must fit in abi::EXINF
:
ⓘ
let captured_value = [0usize; 2]; // too large!
let _ = (move || { dbg!(captured_value); }).into_closure();
The source type must not contain a reference to a local variable:
ⓘ
let captured_value = 42usize;
let _ = (|| { dbg!(&captured_value); }).into_closure(); // capturing by reference