Good Evening, rust sc related question. Is there a possibility provide a callback after async call as a simple closure directly? Or Do I need to define a function annotated with #[callback] and use that as following -> self.callbacks().my_callback()?
There's a lot of magic involved there, in the way callbacks currently work. It's made to look like a simple call, but the full process is that a callback proxy gets generated ( self.callbacks().my_callback() is a callback proxy in fact, it is a generated method), which serializes the proxy closure and saves it temporarily to storage. The callback then loads this data from storage and uses it.
The syntax is what it is, it is the cleanest I could get. I would have loved to make it look like an actual Rust closure, but the compiler doesn't let me hack so deep.
Nope, you have to define a function.
There's a lot of magic involved there, in the way callbacks currently work. It's made to look like a simple call, but the full process is that a callback proxy gets generated ( self.callbacks().my_callback() is a callback proxy in fact, it is a generated method), which serializes the proxy closure and saves it temporarily to storage. The callback then loads this data from storage and uses it. The syntax is what it is, it is the cleanest I could get. I would have loved to make it look like an actual Rust closure, but the compiler doesn't let me hack so deep.