Assigning event loop to struct property - cannot find type `T` in this scope

Hi. I am very very new to rust.
This is a very noob question, but I am kinda stuck so hoping someone can help me out please.

I want to create a window for wgpu purposes.

  1. Create window.
  2. Load content while showing loading process text on window.

The problem is that once you run the event loop you can't return the window data.
So what I was thinking is doing:

  1. Create and cache event loop instance.
  2. Create window instance.
  3. Return to caller who will in turn call a run function to start the event loop.

I can't seem to cache the event loop.
It feels like I am missing something obvious.

use winit::{
    event_loop::{ControlFlow, EventLoop},

use winit::window::Window;

pub struct Application {
    event_loop: EventLoop<T>,
    window: Window

impl Application {
    pub fn new() -> Application {
        let event_loop = EventLoop::new();
        let window = WindowBuilder::new().build(Self.event_loop).unwrap();

        Application {

The error I am getting is

error[E0412]: cannot find type `T` in this scope
  --> src\.\core\
11 |     event_loop: EventLoop<T>,
   |                           ^ not found in this scope
help: there is an enum variant `crate::application::VirtualKeyCode::T` and 1 other; try using the variant's enum
11 |     event_loop: EventLoop<crate::application::VirtualKeyCode>,
   |                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11 |     event_loop: EventLoop<winit::event::VirtualKeyCode>,
   |                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: you might be missing a type parameter
10 | pub struct Application<T> {
   |                       ^^^

As stated by the compiler error, you are missing a generic T parameter in your Application struct:

Consider reading the section on Generic Data Types for Struct Definitions from Chapter 10 in the Rust Book. Good luck!

I think I may have it working

pub struct Application {
    event_loop: EventLoop<()>,
    window: Window

impl Application {
    pub fn new() {
        let event_loop: EventLoop<()> = EventLoop::new();
        let window = WindowBuilder::new().build(&event_loop).unwrap();
        Application {event_loop, window};

    pub fn run() {

but what does "<()>" mean?

() is the unit type. Instances of this type have no fields, methods or associated items and allocate no memory, their size is always 0. The application has an EventLoop where T = (). So if Application calls a function on the EventLoop instance that returns T, it will return the value ().

If every instance of Application is going to use the same value for EventLoop's T type, then you would specify a type (but probably not the unit type). Otherwise you would specify a type generic, as in the example that the compiler gave you.

Correction: The unit type does have methods (from blanket implementations) and any type could be given methods or associated items.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.