Guest User

Untitled

a guest
Feb 17th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. fn main() {
  2. let answer = run_it(Box::new(|| 1 + 1));
  3. println!("Answer: {}", answer);
  4. }
  5.  
  6. trait FnBox {
  7. type Output;
  8.  
  9. fn call(self: Box<Self>) -> Self::Output;
  10. }
  11.  
  12. impl<F: FnOnce()> FnBox for F {
  13. type Output = F::Output;
  14.  
  15. fn call(self: Box<F>) -> F::Output {
  16. self()
  17. }
  18. }
  19.  
  20. fn run_it(f: Box<dyn FnBox<Output = i64>>) -> i64 {
  21. f.call()
  22. }
Add Comment
Please, Sign In to add comment