floooh / sokol-rust

Rust bindings for the sokol headers (https://github.com/floooh/sokol)
zlib License
62 stars 7 forks source link

Avoid static global by using user_data to pass state instead. #30

Closed gw3583 closed 5 months ago

gw3583 commented 6 months ago

This only updates the cube example to avoid a global static. If you're generally happy with this change, I can update the other examples to be similar.

floooh commented 6 months ago

Great fix thanks :) I think it makes sense to apply this to all samples, and that way we are at least safe from the deprecation warning becoming an error at some point.

Eventually I'd like to get rid of the unsafe in the samples entirely, maybe by adding some sort of "SokolApp" wrapper/trait/superclass thingie which somehow would provide a "safe-wrapper" for this unsafe user data handling (internally it would probably do the same thing as your fix).

My Rust-foo isn't good enough to know what a proper idiomatic Rust solution would look like though.

gw3583 commented 5 months ago

Here you go, examples and readme updated. The basic idea of a wrapper with a trait sounds good as a future solution.

floooh commented 5 months ago

Giving this a whirl now...

floooh commented 5 months ago

...and merged. Many thanks, it's nice to see a warning-free build again :)