From 793e57dfa3bb5e29f622b3c3a311be6bca319b86 Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Sat, 4 Jul 2026 00:01:54 -0700 Subject: connect to a GPU ("device") also refactor Error into its own file, it was unwieldy. it really should have been there from the start. for the first time, this compiles without warnings! yay! alas, this is merely the first hump of the camel Force-Push: yes Change-Id: Ib6ec835448af469ccb259776b78a27bbc157c8f0 --- src/error.rs | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/error.rs (limited to 'src/error.rs') diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..39d52b8 --- /dev/null +++ b/src/error.rs @@ -0,0 +1,84 @@ +#![forbid(unsafe_code)] + +#[derive(Debug)] +pub struct Error { + pub message: String, +} +pub type Result = std::result::Result; + +impl std::fmt::Display for Error { + fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) + -> std::result::Result<(), std::fmt::Error> + { + fmt.write_str(&self.message) + } +} + +impl From for Error { + fn from(e: winit::error::EventLoopError) -> Self { + match e { + winit::error::EventLoopError::NotSupported(e) => Self::from(e), + winit::error::EventLoopError::Os(e) => Self::from(e), + winit::error::EventLoopError::RecreationAttempt => Error { + message: + "There may only ever be a single winit event loop.".to_string() + }, + winit::error::EventLoopError::ExitFailure(code) => Error { + message: + format!("Clean unhappy exit with code {} via winit event loop", + code) + } + } + } +} + +impl From for Error { + fn from(e: winit::error::NotSupportedError) -> Self { + Error { + message: + format!("The winit backend does not support an operation: {}", + e.to_string()) + } + } +} + +impl From for Error { + fn from(e: winit::error::OsError) -> Self { + Error { + message: format!("The OS told winit about an error: {}", e.to_string()) + } + } +} + +impl From for Error { + fn from(e: libloading::Error) -> Self { + Error { + message: format!("The dynamic object loader reported an error: {}", + e.to_string()) + } + } +} + +impl From> for Error { + fn from(e: Box) -> Self { + Error { + message: format!("The Vulkan loader reported an error: {}", + e.to_string()) + } + } +} + +impl From for Error { + fn from(e: vulkanalia::vk::ErrorCode) -> Self { + Error { + message: format!("Vulkan gave an error code: {}", e.to_string()) + } + } +} + +pub fn ignore_errors(mut body: impl FnMut() -> Result<()>) -> () { + if let Err(e) = body() { + eprintln!("Error: {}", e); + } +} + -- cgit 1.4.1