rust-windowing / softbuffer

Easily write an image to a window
Apache License 2.0
333 stars 48 forks source link

Use traits to define common backend interface #196

Closed ids1024 closed 9 months ago

ids1024 commented 10 months ago

This still uses enums to dispatch to the backends, but has the *Dispatch types implement the same traits. Nothing about the behavior or performance should change.

If we require backends to implement the same methods, it seems good to use traits for that. Any documentation on the interface implemented by backends can be in one place. The traits can provide default implementations where appropriate.

Hopefully this will help with more refactoring and features.

ids1024 commented 10 months ago

I see some tests are failing since an indirect dev-dependency requires Rust 1.70... not sure what we want to do there.

Though that's unrelated to this change.

ids1024 commented 9 months ago

The alternative to the macro would be Box<dyn ...>, but that's probably not possible anyway with the associated type.

I think the enum_dispatch crate would be a popular solution here, but that adds a proc macro dependency.

notgull commented 9 months ago

I see some tests are failing since an indirect dev-dependency requires Rust 1.70... not sure what we want to do there.

Rebase on master for fixed MSRV CI

ids1024 commented 9 months ago

Added fixes for (unrelated) CI issues, and moved the backends to a backends module.

ids1024 commented 9 months ago

Added a commit that move the backend context/surface ::new methods into traits, making it possible for make_dispatch! to handle new like it handles other methods.