use thiserror::Error;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Error, Debug)]
pub enum Error {
#[error("Windows API error: {0}")]
WindowsError(String),
#[error("Failed to create window: {0}")]
WindowCreation(String),
#[error("Failed to create control: {0}")]
ControlCreation(String),
#[error("XAML parse error: {0}")]
XamlParse(String),
#[error("Resource not found: {0}")]
ResourceNotFound(String),
#[error("Invalid operation: {0}")]
InvalidOperation(String),
#[error("Feature not implemented: {0}")]
NotImplemented(String),
#[error("Application error: {0}")]
Application(String),
#[error("Initialization error: {0}")]
Initialization(String),
#[error("Synchronization error: {0}")]
Synchronization(String),
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("UTF-8 error: {0}")]
Utf8(#[from] std::string::FromUtf8Error),
#[error("{0}")]
Other(String),
}
impl Error {
pub fn windows(msg: impl Into<String>) -> Self {
Self::WindowsError(msg.into())
}
pub fn window_creation(msg: impl Into<String>) -> Self {
Self::WindowCreation(msg.into())
}
pub fn control_creation(msg: impl Into<String>) -> Self {
Self::ControlCreation(msg.into())
}
pub fn xaml_parse(msg: impl Into<String>) -> Self {
Self::XamlParse(msg.into())
}
pub fn resource_not_found(msg: impl Into<String>) -> Self {
Self::ResourceNotFound(msg.into())
}
pub fn invalid_operation(msg: impl Into<String>) -> Self {
Self::InvalidOperation(msg.into())
}
pub fn not_implemented(msg: impl Into<String>) -> Self {
Self::NotImplemented(msg.into())
}
pub fn application(msg: impl Into<String>) -> Self {
Self::Application(msg.into())
}
pub fn initialization(msg: impl Into<String>) -> Self {
Self::Initialization(msg.into())
}
pub fn synchronization(msg: impl Into<String>) -> Self {
Self::Synchronization(msg.into())
}
}
impl From<windows::core::Error> for Error {
fn from(err: windows::core::Error) -> Self {
Error::WindowsError(format!("{:?}", err))
}
}
impl From<&str> for Error {
fn from(s: &str) -> Self {
Error::Other(s.to_string())
}
}
impl From<String> for Error {
fn from(s: String) -> Self {
Error::Other(s)
}
}