2022-12-20 08:43:26 -07:00
|
|
|
use raw_window_handle::{RawDisplayHandle, RawWindowHandle};
|
2022-12-22 12:35:18 -08:00
|
|
|
use std::error::Error;
|
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-27 12:23:27 -08:00
|
|
|
pub enum SoftBufferError {
|
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,
|
2022-12-22 12:35:18 -08:00
|
|
|
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")]
|
2022-12-22 12:35:18 -08:00
|
|
|
PlatformError(Option<String>, Option<Box<dyn Error>>),
|
2022-01-16 08:59:29 -06:00
|
|
|
}
|
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-22 12:35:18 -08:00
|
|
|
pub(crate) fn unwrap<T, E: std::error::Error + 'static>(
|
|
|
|
|
res: Result<T, E>,
|
|
|
|
|
str: &str,
|
2022-12-27 12:23:27 -08:00
|
|
|
) -> Result<T, SoftBufferError> {
|
2022-12-22 12:35:18 -08:00
|
|
|
match res {
|
2022-01-19 21:11:20 -06:00
|
|
|
Ok(t) => Ok(t),
|
2022-12-27 12:23:27 -08:00
|
|
|
Err(e) => Err(SoftBufferError::PlatformError(
|
2022-12-22 12:35:18 -08:00
|
|
|
Some(str.into()),
|
|
|
|
|
Some(Box::new(e)),
|
|
|
|
|
)),
|
2022-01-19 21:11:20 -06:00
|
|
|
}
|
2022-12-20 08:43:26 -07:00
|
|
|
}
|