fn_box

Crates.iofn_box
lib.rsfn_box
version1.0.5
sourcesrc
created_at2014-12-22 11:40:30.261253
updated_at2015-12-11 23:58:51.47213
descriptionBox up your FnOnces
homepage
repositoryhttps://github.com/nathan7/fn_box
max_upload_size
id623
size2,536
edef (edef1c)

documentation

README

Build Status

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);
Commit count: 0

cargo fmt