bela-rs icon indicating copy to clipboard operation
bela-rs copied to clipboard

#[derive(UserData)]

Open andrewcsmith opened this issue 7 years ago • 2 comments

UserData is basically all boilerplate...

andrewcsmith avatar Apr 02 '18 19:04 andrewcsmith

it's also mostly unused! In principle, it could be used by the wrapping main() to pass arguments to setup(), render(), cleanup(), but in practice many times global variables can do the same job.

giuliomoro avatar Apr 02 '18 22:04 giuliomoro

@giuliomoro for an idiomatic API, we should actually eliminate global variables altogether. Mutable global variables are unsafe in Rust (and, technically, in general) since they're both mutable and shared. Basically, for this library anyway, even the callback functions are stored in UserData!

What I meant in this issue is that all the bits of UserData that define the callbacks should probably be provided by a macro, rather than by writing out those complicated signatures by hand. The idea here is that the type-safety of Rust guarantees at compile time that you're always using the same struct for UserData.

I'm hoping to teach a workshop to my class at UCSC, and I'll pull the stuff together for the internet...

andrewcsmith avatar Apr 03 '18 01:04 andrewcsmith