I'm trying to make some higher order programs in Rust, but I'm having difficulty closing. Here is a piece of code that illustrates one of the problems that I am having:
pub enum Foo { Bar(Box<FnOnce(i32)>), } pub fn app(i: i32, arg: Foo) { match arg { Foo::Bar(f) => f(i), } }
When I compile this piece of code, I get the following error message:
error[E0161]: cannot move a value of type std::ops::FnOnce(i32) + 'static: the size of std::ops::FnOnce(i32) + 'static cannot be statically determined --> src/main.rs:7:24 | 7 | Foo::Bar(f) => f(i), | ^
Since I put the function in Box , I would think that this would deal with the compiler problem without knowing the size. How to compile the above program?
rust
svenningsson
source share