softbuffer/src/error.rs

47 lines
1.4 KiB
Rust
Raw Normal View History

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]
pub enum SoftBufferError {
#[error(
"The provided display returned an unsupported platform: {human_readable_display_platform_name}."
)]
UnsupportedDisplayPlatform {
human_readable_display_platform_name: &'static str,
display_handle: RawDisplayHandle,
},
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
)]
UnsupportedWindowPlatform {
human_readable_window_platform_name: &'static str,
human_readable_display_platform_name: &'static str,
window_handle: RawWindowHandle,
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,
) -> 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),
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
}
}