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

event_loop.run() use "self" but not "&mut self", in branch v0.22.x #1316

Closed
TakWolf opened this issue Dec 10, 2019 · 1 comment
Closed

event_loop.run() use "self" but not "&mut self", in branch v0.22.x #1316

TakWolf opened this issue Dec 10, 2019 · 1 comment
Labels
F - question There's no such thing as a stupid one

Comments

@TakWolf
Copy link
Contributor

TakWolf commented Dec 10, 2019

pub fn run<F>(self, event_handler: F) -> !

#459

    pub fn run<F>(self, event_handler: F) -> !
    where
        F: 'static + FnMut(Event<T>, &EventLoopWindowTarget<T>, &mut ControlFlow),
    {
        self.event_loop.run(event_handler)
    }

Is there necessary by design or a typo?(event_loop.run_forever() use "&mut self")

I need hold a event_loop instance in a struct, like:

pub struct MyStruct {
    event_loop: winit::event_loop::EventLoop<()>,
}

What is the correct way?

@goddessfreya goddessfreya added the F - question There's no such thing as a stupid one label Dec 11, 2019
@TakWolf
Copy link
Contributor Author

TakWolf commented Dec 12, 2019

I found on Windows, MacOS, Linux, Web and Android, the implement can use "&mut self".

But on iOS:

pub fn run<F>(self, event_handler: F) -> !

    pub fn run<F>(self, event_handler: F) -> !
    where
        F: 'static + FnMut(Event<T>, &RootEventLoopWindowTarget<T>, &mut ControlFlow),
    {
        unsafe {
            let application: *mut c_void = msg_send![class!(UIApplication), sharedApplication];
            assert_eq!(
                application,
                ptr::null_mut(),
                "\
                 `EventLoop` cannot be `run` after a call to `UIApplicationMain` on iOS\n\
                 Note: `EventLoop::run` calls `UIApplicationMain` on iOS"
            );
            app_state::will_launch(Box::new(EventLoopHandler {
                f: event_handler,
                event_loop: self.window_target,   // <---------- there is a attr move
            }));

            UIApplicationMain(
                0,
                ptr::null(),
                nil,
                NSString::alloc(nil).init_str("AppDelegate"),
            );
            unreachable!()
        }
    }

@TakWolf TakWolf closed this as completed Dec 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F - question There's no such thing as a stupid one
Development

No branches or pull requests

2 participants