Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn main() {
- let answer = run_it(Box::new(|| 1 + 1));
- println!("Answer: {}", answer);
- }
- trait FnBox {
- type Output;
- fn call(self: Box<Self>) -> Self::Output;
- }
- impl<F: FnOnce()> FnBox for F {
- type Output = F::Output;
- fn call(self: Box<F>) -> F::Output {
- self()
- }
- }
- fn run_it(f: Box<dyn FnBox<Output = i64>>) -> i64 {
- f.call()
- }
Add Comment
Please, Sign In to add comment