rend3 icon indicating copy to clipboard operation
rend3 copied to clipboard

Can't use user types in framework's event loop

Open John-Nagle opened this issue 2 years ago • 1 comments

Rend3's framework has a feature which allows specifying a Winit user event type for the framework, so that user messages can be added to the event queue. One use case is egui menus, where a menu result can be turned into an event and queued to be handled as a Winit event.

App is defined with a generic parameter for the use event type. The default value is ().

The examples for the framework use

impl rend3_framework::App for Ui

which generates the default user event type of (). That works. A user event type can be specified:

impl rend3_framework::App<BoxedGuiEvent> for Ui

The compiler accepts that, but there's trouble at the function start within the framework:

error[E0277]: the trait bound `Ui: App` is not satisfied
   --> src/main.rs:358:5
    |
358 |     rend3_framework::start(
    |     ^^^^^^^^^^^^^^^^^^^^^^ the trait `App` is not implemented for `Ui`
    |
    = help: the following implementations were found:
              <Ui as App<Box<GuiEvent>>>
note: required by a bound in `start`
   --> /home/john/.cargo/git/checkouts/rend3-e03f89403de3386a/74d1e12/rend3-framework/src/lib.rs:393:17
    |
393 | pub fn start<A: App + 'static>(app: A, window_builder: WindowBuilder) {
    |                 ^^^ required by this bound in `start`

For more information about this error, try `rustc --explain E0277`.

In a discussion on the Rust help forum, the advice I got was that

pub fn start<A: App + 'static>(app: A, window_builder: WindowBuilder) {

needs to be

pub fn start<T: 'static, A: App<T> + 'static>(app: A, window_builder: WindowBuilder) {

I was told that App means "use default only", while App<T> means "allow type parameter". This makes sense. The declaration of the App trait works that way. I haven't tried modifying rend3-framework to test, though. Too much chance I'd break something.

Medium level problem. I can work around this by making my own user event queue using crossbeam_channel.

John-Nagle avatar Jun 27 '22 17:06 John-Nagle

I believe this should be fixed now.

cwfitzgerald avatar Jul 21 '22 06:07 cwfitzgerald