use windows::core as wcore;
#[derive(Debug)]
pub enum Error {
Windows(wcore::Error),
NoDispatch,
NoDispid,
TypeMismatch {
expected: &'static str,
actual: u16,
},
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Error::Windows(e) => write!(f, "windows error: {e}"),
Error::NoDispatch => write!(f, "VARIANT does not contain an IDispatch"),
Error::NoDispid => write!(f, "GetIDsOfNames returned no dispid"),
Error::TypeMismatch { expected, actual } => write!(
f,
"type mismatch: expected {expected}, got VARENUM(0x{actual:04X})"
),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::Windows(e) => Some(e),
_ => None,
}
}
}
impl From<wcore::Error> for Error {
fn from(e: wcore::Error) -> Self {
Error::Windows(e)
}
}
pub type Result<T> = std::result::Result<T, Error>;