softbuffer/src/error.rs

35 lines
1.1 KiB
Rust
Raw Normal View History

2022-01-16 08:59:29 -06:00
use std::error::Error;
use raw_window_handle::{RawDisplayHandle, RawWindowHandle};
2022-01-16 08:59:29 -06:00
use thiserror::Error;
#[derive(Error, Debug)]
2022-12-21 17:26:09 -08:00
#[non_exhaustive]
pub enum SwBufError {
2022-01-16 08:59:29 -06:00
#[error(
"The provided window returned an unsupported platform: {human_readable_window_platform_name}, {human_readable_display_platform_name}."
2022-01-16 08:59:29 -06:00
)]
UnsupportedPlatform {
human_readable_window_platform_name: &'static str,
human_readable_display_platform_name: &'static str,
window_handle: RawWindowHandle,
display_handle: RawDisplayHandle
2022-01-16 08:59:29 -06:00
},
2022-12-21 17:26:09 -08:00
#[error("The provided window handle is null.")]
IncompleteWindowHandle,
#[error("The provided display handle is null.")]
IncompleteDisplayHandle,
2022-01-16 08:59:29 -06:00
#[error("Platform error")]
PlatformError(Option<String>, Option<Box<dyn Error>>)
}
2022-01-19 21:11:20 -06:00
2022-02-23 19:13:26 +11:00
#[allow(unused)] // This isn't used on all platforms
pub(crate) fn unwrap<T, E: std::error::Error + 'static>(res: Result<T, E>, str: &str) -> Result<T, SwBufError>{
2022-01-19 21:11:20 -06:00
match res{
Ok(t) => Ok(t),
2022-12-20 07:10:11 -07:00
Err(e) => Err(SwBufError::PlatformError(Some(str.into()), Some(Box::new(e))))
2022-01-19 21:11:20 -06:00
}
}