1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use std::marker::PhantomData;
use crate::{
runtime::Runtime,
window::{RuntimeWindow, Window, WindowCreator},
};
pub trait Application: Sized + Send + Sync {
fn initialize(&mut self) {}
fn should_exit(&mut self) -> bool {
Self::open_window_count() == 0
}
#[must_use]
fn open_window_count() -> usize {
RuntimeWindow::count()
}
}
pub struct SingleWindowApplication<T> {
phantom: PhantomData<T>,
}
impl<T> Application for SingleWindowApplication<T> where T: Window + WindowCreator + 'static {}
impl<T> SingleWindowApplication<T>
where
T: Window + WindowCreator + 'static,
{
pub fn run(window: T) -> ! {
let app = Self {
phantom: PhantomData::default(),
};
Runtime::new(app).run(window.get_window_builder(), window)
}
}