softbuffer/src/error.rs
Ian Douglas Scott fc1bba64ab Rename SwBufError back to SoftBufferError
This seems to be the last thing left over from the `swbuf` rename.
2022-12-27 12:57:26 -08:00

40 lines
1.2 KiB
Rust

use raw_window_handle::{RawDisplayHandle, RawWindowHandle};
use std::error::Error;
use thiserror::Error;
#[derive(Error, Debug)]
#[non_exhaustive]
pub enum SoftBufferError {
#[error(
"The provided window returned an unsupported platform: {human_readable_window_platform_name}, {human_readable_display_platform_name}."
)]
UnsupportedPlatform {
human_readable_window_platform_name: &'static str,
human_readable_display_platform_name: &'static str,
window_handle: RawWindowHandle,
display_handle: RawDisplayHandle,
},
#[error("The provided window handle is null.")]
IncompleteWindowHandle,
#[error("The provided display handle is null.")]
IncompleteDisplayHandle,
#[error("Platform error")]
PlatformError(Option<String>, Option<Box<dyn Error>>),
}
#[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, SoftBufferError> {
match res {
Ok(t) => Ok(t),
Err(e) => Err(SoftBufferError::PlatformError(
Some(str.into()),
Some(Box::new(e)),
)),
}
}