]>
Commit | Line | Data |
---|---|---|
1 | impl WIN32_ERROR { | |
2 | #[inline] | |
3 | pub const fn is_ok(self) -> bool { | |
4 | self.0 == 0 | |
5 | } | |
6 | #[inline] | |
7 | pub const fn is_err(self) -> bool { | |
8 | !self.is_ok() | |
9 | } | |
10 | #[inline] | |
11 | pub const fn to_hresult(self) -> ::windows::core::HRESULT { | |
12 | ::windows::core::HRESULT(if self.0 == 0 { self.0 } else { (self.0 & 0x0000_FFFF) | (7 << 16) | 0x8000_0000 } as _) | |
13 | } | |
14 | #[inline] | |
15 | pub fn from_error(error: &::windows::core::Error) -> ::core::option::Option<Self> { | |
16 | let hresult = error.code().0 as u32; | |
17 | if ((hresult >> 16) & 0x7FF) == 7 { | |
18 | Some(Self(hresult & 0xFFFF)) | |
19 | } else { | |
20 | None | |
21 | } | |
22 | } | |
23 | #[inline] | |
24 | pub const fn ok(self) -> ::windows::core::Result<()> { | |
25 | if self.is_ok() { | |
26 | Ok(()) | |
27 | } else { | |
28 | Err(::windows::core::Error { code: self.to_hresult(), info: None }) | |
29 | } | |
30 | } | |
31 | } | |
32 | impl ::core::convert::From<WIN32_ERROR> for ::windows::core::HRESULT { | |
33 | fn from(value: WIN32_ERROR) -> Self { | |
34 | value.to_hresult() | |
35 | } | |
36 | } | |
37 | impl ::core::convert::From<WIN32_ERROR> for ::windows::core::Error { | |
38 | fn from(value: WIN32_ERROR) -> Self { | |
39 | Self { code: value.to_hresult(), info: None } | |
40 | } | |
41 | } |