/
ntstatus.rs
39 lines (33 loc) · 1.08 KB
/
ntstatus.rs
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
31
32
33
34
35
36
37
38
39
use super::*;
pub fn gen_ntstatus() -> TokenStream {
quote! {
#[repr(transparent)]
#[derive(::core::default::Default, ::core::clone::Clone, ::core::marker::Copy, ::core::cmp::PartialEq, ::core::cmp::Eq, ::core::fmt::Debug)]
pub struct NTSTATUS(pub i32);
impl NTSTATUS {
#[inline]
pub const fn is_ok(self) -> bool {
self.0 >= 0
}
#[inline]
pub const fn is_err(self) -> bool {
!self.is_ok()
}
#[inline]
pub const fn to_hresult(self) -> ::windows::core::HRESULT {
::windows::core::HRESULT(self.0 | 0x1000_0000)
}
#[inline]
pub fn ok(self) -> ::windows::core::Result<()> {
if self.is_ok() {
Ok(())
} else {
Err(::windows::core::Error::fast_error(self.to_hresult()))
}
}
}
unsafe impl ::windows::core::Abi for NTSTATUS {
type Abi = Self;
}
}
}