Add AppError
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 21m29s
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 21m29s
This commit is contained in:
parent
f4694157ab
commit
df99ef3a3f
4 changed files with 47 additions and 22 deletions
|
@ -7,7 +7,15 @@ pub enum AppExit {
|
|||
Error(Box<dyn Error>),
|
||||
}
|
||||
|
||||
pub type RunnerFn = Box<dyn FnOnce() -> AppExit>;
|
||||
pub type RunnerFn = Box<dyn FnOnce(App) -> AppExit>;
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum AppError {
|
||||
#[error("Runner is not set")]
|
||||
RunnerNotSet,
|
||||
#[error("Runner returned an error : {0}")]
|
||||
RunnerError(Box<dyn Error>),
|
||||
}
|
||||
|
||||
pub struct App {
|
||||
world: World,
|
||||
|
@ -35,16 +43,13 @@ impl App {
|
|||
&self.world
|
||||
}
|
||||
|
||||
pub fn run(&mut self) -> Result<(), Box<dyn Error>> {
|
||||
pub fn run(mut self) -> Result<(), AppError> {
|
||||
match self.runner.take() {
|
||||
Some(runner) => match runner() {
|
||||
Some(runner) => match runner(self) {
|
||||
AppExit::Success => Ok(()),
|
||||
AppExit::Error(e) => Err(e),
|
||||
AppExit::Error(e) => Err(AppError::RunnerError(e)),
|
||||
},
|
||||
None => Err(Box::new(std::io::Error::new(
|
||||
std::io::ErrorKind::Other,
|
||||
"runner is not set",
|
||||
))),
|
||||
None => Err(AppError::RunnerNotSet),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -5,25 +5,23 @@ pub mod core;
|
|||
pub mod game;
|
||||
pub mod vulkan;
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
fn main() -> Result<(), impl Error> {
|
||||
env_logger::init();
|
||||
|
||||
run_old_app()
|
||||
run_new_app()
|
||||
}
|
||||
|
||||
fn run_new_app() -> Result<(), Box<dyn Error>> {
|
||||
let mut app = core::app::App::default();
|
||||
fn run_new_app() -> Result<(), impl Error> {
|
||||
let app = core::app::App::default();
|
||||
app.run()
|
||||
}
|
||||
|
||||
fn run_old_app() -> Result<(), Box<dyn Error>> {
|
||||
fn run_old_app() -> Result<(), impl Error> {
|
||||
let event_loop = EventLoop::new().unwrap();
|
||||
event_loop.set_control_flow(ControlFlow::Poll);
|
||||
|
||||
let vulkan_context = vulkan::vulkan_context::VulkanContext::from(&event_loop);
|
||||
let mut app = core::old_app::App::from(vulkan_context);
|
||||
|
||||
event_loop.run_app(&mut app).map_err(Box::new)?;
|
||||
|
||||
Ok(())
|
||||
event_loop.run_app(&mut app)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue