Share via

Rust (windows-rs): TypedEventHandler useless

Paul 21 Reputation points
2022-11-27T16:16:24.507+00:00

Hi,
i wanted to listen for the IActivatedEventArgs on startup for my rust windows-rs application. I currently have floowing Code in my Initialize function of the CoreAppView (IFramwrokView_Impl):

fn Initialize(&self, applicationview: &Option<CoreApplicationView>) -> Result<()> {  
        let app_view: &CoreApplicationView = applicationview.as_ref().unwrap();  
        let event_handler: TypedEventHandler<CoreApplicationView, IActivatedEventArgs> =  
            TypedEventHandler::new(| arg1, arg2| self.on_activated(arg1, arg2));  
        app_view.Activated(&event_handler);  
        Ok(())  
    }  

borrowed data escapes outside of associated function
self escapes the associated function body hererustcClick for full compiler diagnostic
main.rs(31, 19): self is a reference that is only valid in the associated function body
main.rs(31, 19): let's call the lifetime of this reference '1
borrowed data escapes outside of associated function
argument requires that '1 must outlive 'staticrustcClick for full compiler diagnostic
main.rs(31, 19): self is a reference that is only valid in the associated function body
main.rs(31, 19): let's call the lifetime of this reference '1

I cannot access self.on_activated in the TypedEventHandler because of a borrow error concerning self. How am i suposed to do this as i have no clue why you wanna have these colsures when you cannot access the outer scope?

Developer technologies | Universal Windows Platform (UWP)

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.