Uses old Rust 2015
1.0.5 |
|
---|---|
1.0.4 |
|
1.0.2 |
|
1.0.1 |
|
#65 in #args
3KB
58 lines
fn_box
Box up your FnOnces!
API
trait FnBox<Args, Result = ()> {
extern "rust-call" fn call_box(self: Box<Self>, args: Args) -> Result;
}
impl<F, Args, Result> FnBox<Args, Result> for F where F: FnOnce<Args, Result> { … }
#[cfg(not(when_coherence_is_fixed))]
impl<'a> FnOnce() for Box<FnBox() + 'a> { … }
#[cfg(when_coherence_is_fixed)]
impl<'a, Args, Result> FnOnce<Args, Result> for Box<FnBox<Args, Result> + 'a> { … }
Usage
let hello: Box<FnBox()> = Box::new(move || { println!("hello world!") });
hello();
let plus_one: Box<FnBox(_) -> _> = Box::new(move |x: i32| { x + 1 });
assert_eq!(plus_one.call_box((3,)), 4);