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

Make RenderElement implementations generic to reduce duplication #682

Merged
merged 1 commit into from
Aug 5, 2024

Conversation

ids1024
Copy link
Member

@ids1024 ids1024 commented Aug 5, 2024

It would make sense to have a bound like for<'frame> R::Frame<'frame>: AsGlowFrame<'frame>. But that appears to not behave properly due to current limitations of the borrow checker: https://blog.rust-lang.org/2022/10/28/gats-stabilization.html#implied-static-requirement-from-higher-ranked-trait-bounds

Instead, this makes glow_frame and glow_frame_mut associated functions of the AsGlowRenderer trait. Then it is pretty straightforward to make the RenderElement implementations generic using that and FromGlesError.

It would make sense to make Self::Error: FromGlessError a requirement of the AsGlowRenderer trait, but due to the lack of implied bounds support, that produces a bunch of errors about missing bounds. If Rustc improves that eventually, some bounds could be cleaned up a bit: rust-lang/rust#44491

It would make sense to have a bound like
`for<'frame> R::Frame<'frame>: AsGlowFrame<'frame>`. But that appears to
not behave properly due to current limitations of the borrow checker:
https://blog.rust-lang.org/2022/10/28/gats-stabilization.html#implied-static-requirement-from-higher-ranked-trait-bounds

Instead, this makes `glow_frame` and `glow_frame_mut` associated
functions of the `AsGlowRenderer` trait. Then it is pretty
straightforward to make the `RenderElement` implementations generic
using that and `FromGlesError`.

It would make sense to make `Self::Error: FromGlessError` a requirement
of the `AsGlowRenderer` trait, but due to the lack of implied bounds
support, that produces a bunch of errors about missing bounds. If Rustc
improves that eventually, some bounds could be cleaned up a bit:
rust-lang/rust#44491
Copy link
Member

@Drakulix Drakulix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead, this makes glow_frame and glow_frame_mut associated functions of the AsGlowRenderer trait. Then it is pretty straightforward to make the RenderElement implementations generic using that and FromGlesError.

Oh neat, that is such a good, although a little clunky, solution to this problem!

@Drakulix Drakulix merged commit 4748916 into master Aug 5, 2024
7 checks passed
@Drakulix Drakulix deleted the render-elements branch August 5, 2024 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants