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
33
Cargo.lock
generated
33
Cargo.lock
generated
|
@ -65,7 +65,7 @@ dependencies = [
|
|||
"ndk-context",
|
||||
"ndk-sys",
|
||||
"num_enum",
|
||||
"thiserror",
|
||||
"thiserror 1.0.69",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -384,7 +384,7 @@ dependencies = [
|
|||
"polling",
|
||||
"rustix",
|
||||
"slab",
|
||||
"thiserror",
|
||||
"thiserror 1.0.69",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -863,7 +863,7 @@ dependencies = [
|
|||
"combine",
|
||||
"jni-sys",
|
||||
"log",
|
||||
"thiserror",
|
||||
"thiserror 1.0.69",
|
||||
"walkdir",
|
||||
"windows-sys 0.45.0",
|
||||
]
|
||||
|
@ -975,7 +975,7 @@ dependencies = [
|
|||
"ndk-sys",
|
||||
"num_enum",
|
||||
"raw-window-handle",
|
||||
"thiserror",
|
||||
"thiserror 1.0.69",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1537,6 +1537,7 @@ dependencies = [
|
|||
"env_logger",
|
||||
"glam",
|
||||
"log",
|
||||
"thiserror 2.0.12",
|
||||
"vulkano",
|
||||
"vulkano-shaders",
|
||||
"winit",
|
||||
|
@ -1695,7 +1696,7 @@ dependencies = [
|
|||
"log",
|
||||
"memmap2",
|
||||
"rustix",
|
||||
"thiserror",
|
||||
"thiserror 1.0.69",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
"wayland-csd-frame",
|
||||
|
@ -1738,7 +1739,16 @@ version = "1.0.69"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
"thiserror-impl 1.0.69",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "2.0.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708"
|
||||
dependencies = [
|
||||
"thiserror-impl 2.0.12",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1752,6 +1762,17 @@ dependencies = [
|
|||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "2.0.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thread_local"
|
||||
version = "1.1.8"
|
||||
|
|
|
@ -7,6 +7,7 @@ publish = false
|
|||
|
||||
[dependencies]
|
||||
anyhow = "1.0"
|
||||
thiserror = "2.0"
|
||||
winit = { version = "0.30", features = ["rwh_06"] }
|
||||
|
||||
vulkano = "0.35"
|
||||
|
|
|
@ -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
Reference in a new issue