1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use windows::Win32::Foundation::D2DERR_RECREATE_TARGET;

#[derive(Clone, PartialEq, Eq, Debug, thiserror::Error)]
pub enum Error {
    #[error("RecreateTarget")]
    RecreateTarget,
    #[error("{0}")]
    Other(windows::core::Error),
}

impl From<windows::core::Error> for Error {
    fn from(src: windows::core::Error) -> Self {
        if src.code() == D2DERR_RECREATE_TARGET {
            Self::RecreateTarget
        } else {
            Self::Other(src)
        }
    }
}

impl From<windows::core::HRESULT> for Error {
    fn from(src: windows::core::HRESULT) -> Self {
        match src {
            D2DERR_RECREATE_TARGET => Self::RecreateTarget,
            _ => Self::Other(src.into()),
        }
    }
}

pub type Result<T> = ::core::result::Result<T, Error>;