diff options
| author | Irene Knapp <ireneista@irenes.space> | 2026-07-04 00:01:54 -0700 |
|---|---|---|
| committer | Irene Knapp <ireneista@irenes.space> | 2026-07-04 00:15:29 -0700 |
| commit | 793e57dfa3bb5e29f622b3c3a311be6bca319b86 (patch) | |
| tree | 272b8bec5da5bf4102e30bd7a46b9dc45ad741e8 /src/error.rs | |
| parent | 622e7cc99346b2634a162163193ce4561131d1d2 (diff) | |
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
Diffstat (limited to 'src/error.rs')
| -rw-r--r-- | src/error.rs | 84 |
1 files changed, 84 insertions, 0 deletions
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<T> = std::result::Result<T, Error>; + +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<winit::error::EventLoopError> 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<winit::error::NotSupportedError> 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<winit::error::OsError> for Error { + fn from(e: winit::error::OsError) -> Self { + Error { + message: format!("The OS told winit about an error: {}", e.to_string()) + } + } +} + +impl From<libloading::Error> for Error { + fn from(e: libloading::Error) -> Self { + Error { + message: format!("The dynamic object loader reported an error: {}", + e.to_string()) + } + } +} + +impl From<Box<dyn vulkanalia::loader::LoaderError>> for Error { + fn from(e: Box<dyn vulkanalia::loader::LoaderError>) -> Self { + Error { + message: format!("The Vulkan loader reported an error: {}", + e.to_string()) + } + } +} + +impl From<vulkanalia::vk::ErrorCode> 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); + } +} + |