Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DerivedDrawHandle #226

Closed
wants to merge 1 commit into from
Closed

Add DerivedDrawHandle #226

wants to merge 1 commit into from

Conversation

dhardy
Copy link
Collaborator

@dhardy dhardy commented Jul 30, 2021

The intention here is to allow themes like ShadedTheme to be incomplete by providing some base implementation to fill in missing methods. Currently ShadedTheme does effectively the same thing but with stub functions; part of the point of this change is to make it non-breaking (or less breaking) to extend DrawHandle and SizeHandle.

Blocker:

error[E0119]: conflicting implementations of trait `draw::handle::DrawHandle` for type `std::boxed::Box<_>`
   --> src/draw/handle.rs:737:1
    |
568 | impl<D: DerivedDrawHandle> DrawHandle for D {
    | ------------------------------------------- first implementation here
...
737 | impl<H: DrawHandle> DrawHandle for Box<H> {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `std::boxed::Box<_>`
    |
    = note: downstream crates may implement trait `draw::handle::DerivedDrawHandle` for type `std::boxed::Box<_>`

Fixing this would need some form of specialisation or negative trait bounds (e.g. rust-lang/rfcs/issues/1834).

An alternative would be to add the base* methods and default implementations to DrawHandle itself; this is less desirable since themes without a base (e.g. FlatTheme) would be forced to panic in the base* methods, resulting in run-time failure if the theme is incomplete (and only then on examples which use those size/draw methods).

Incomplete in this PR:

  • switch ShadedTheme to impl DerivedDrawHandle
  • add DerivedSizeHandle

@dhardy
Copy link
Collaborator Author

dhardy commented Jun 10, 2022

This is made obsolete by #327, though is potentially another alternative.

@dhardy dhardy closed this Jun 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant