// Copyright 2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 or the MIT license // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. use alloc::boxed::Box; use core::kinds::Send; use core::ops::FnOnce; pub struct Thunk { invoke: Box+Send> } impl Thunk<(),R> { pub fn new(func: F) -> Thunk<(),R> where F : FnOnce() -> R, F : Send { Thunk::with_arg(move|: ()| func()) } } impl Thunk { pub fn with_arg(func: F) -> Thunk where F : FnOnce(A) -> R, F : Send { Thunk { invoke: box func } } pub fn invoke(self, arg: A) -> R { self.invoke.invoke(arg) } } pub trait Invoke { fn invoke(self: Box, arg: A) -> R; } impl Invoke for F where F : FnOnce(A) -> R { fn invoke(self: Box, arg: A) -> R { let f = *self; f(arg) } }