1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // Because this module is temporary...
12 #![allow(missing_docs)]
13 #![unstable(feature = "std_misc")]
15 use alloc::boxed::Box;
16 use core::marker::Send;
17 use core::ops::FnOnce;
19 pub struct Thunk<A=(),R=()> {
20 invoke: Box<Invoke<A,R>+Send>
24 pub fn new<F>(func: F) -> Thunk<(),R>
25 where F : FnOnce() -> R, F : Send
27 Thunk::with_arg(move|: ()| func())
31 impl<A,R> Thunk<A,R> {
32 pub fn with_arg<F>(func: F) -> Thunk<A,R>
33 where F : FnOnce(A) -> R, F : Send
40 pub fn invoke(self, arg: A) -> R {
41 self.invoke.invoke(arg)
45 pub trait Invoke<A=(),R=()> {
46 fn invoke(self: Box<Self>, arg: A) -> R;
49 impl<A,R,F> Invoke<A,R> for F
50 where F : FnOnce(A) -> R
52 fn invoke(self: Box<F>, arg: A) -> R {