My goal is to let the user add a closure to a struct that accepts the struct as an input, as a way to add a sort of custom method.
Its purpose is to update the struct before that struct handles certain events. I plan to add a second one to run after events as well.
Here is a minimal example of the issue I have:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=f8119ccf560548ed681f39ece0e07711
And the error I get:
error[E0644]: closure/coroutine type that references itself
--> src/main.rs:8:15
|
8 | func: |_| {}
| ^^^ cyclic type of infinite size
|
= note: closures cannot capture themselves or take themselves as argument;
Shouldn't this not be of infinite size since I took in the struct containing the closure by reference?
Is my only option to box it up and use dynamic dispatch?
A browser interface to the Rust compiler to experiment with the language