2022-01-16 08:59:29 -06:00
|
|
|
use std::error::Error;
|
2022-12-20 08:43:26 -07:00
|
|
|
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]
|
2022-12-20 08:43:26 -07:00
|
|
|
pub enum SwBufError {
|
2022-01-16 08:59:29 -06:00
|
|
|
#[error(
|
2022-08-24 00:16:20 -05:00
|
|
|
"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 {
|
2022-08-24 00:16:20 -05:00
|
|
|
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
|
2022-12-20 08:43:26 -07:00
|
|
|
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
|
|
|
}
|
2022-12-20 08:43:26 -07:00
|
|
|
}
|