pub struct NtStatus(/* private fields */);Expand description
An NTSTATUS, the signed status the native API and the drivers beneath it report in.
An i32. The layout, from the top: a two-bit severity, the customer bit, a bit that
HResult::from_ntstatus sets when it makes an HRESULT of one, a twelve-bit facility, and a
16-bit code. It is a number space of its own, not Win32Error’s or
HResult’s, and there is no conversion to a Win32 code here: that is RtlNtStatusToDosError,
an Rtl* call, which this repository’s rule on documented interfaces excludes. The one
conversion that is a macro, HRESULT_FROM_NT, is HResult::from_ntstatus.
NT_SUCCESS is status >= 0, so a success and an informational status are both successes, and a
warning is not: is_success and into_result follow
that. It is not an Error, because a success is a value of this type.
§Example
use win_error_codes::{HResult, NtSeverity, NtStatus};
// STATUS_ACCESS_VIOLATION.
let status = NtStatus::from_raw(0xC000_0005_u32.cast_signed());
assert_eq!(status.severity(), NtSeverity::Error);
assert!(!status.is_success());
assert_eq!(status.to_string(), "0xC0000005");
// STATUS_PENDING is a success.
assert!(NtStatus::from_raw(0x103).is_success());
// HRESULT_FROM_NT sets one bit, and the status is recovered by clearing it.
let hresult = HResult::from_ntstatus(status);
assert_eq!(hresult.raw().cast_unsigned(), 0xD000_0005);
assert_eq!(hresult.ntstatus(), Some(status));Implementations§
Source§impl NtStatus
impl NtStatus
Sourcepub const fn severity(self) -> NtSeverity
pub const fn severity(self) -> NtSeverity
The severity, from the top two bits.
Sourcepub const fn is_success(self) -> bool
pub const fn is_success(self) -> bool
NT_SUCCESS: whether the status is not negative, which is a success or an informational
status. A warning is not.
Sourcepub const fn is_information(self) -> bool
pub const fn is_information(self) -> bool
NT_INFORMATION: whether the severity is informational.
Sourcepub const fn is_warning(self) -> bool
pub const fn is_warning(self) -> bool
NT_WARNING: whether the severity is a warning.
Sourcepub const fn into_result(self) -> Result<(), Self>
pub const fn into_result(self) -> Result<(), Self>
Ok for NT_SUCCESS and Err carrying this status for anything else, a warning included.
§Errors
This status, when it is a warning or an error.
Sourcepub const fn is_customer(self) -> bool
pub const fn is_customer(self) -> bool
Whether the customer bit is set: a code a third party defined, not Microsoft.
Trait Implementations§
impl Copy for NtStatus
Source§impl Debug for NtStatus
NtStatus(0xC0000005), in hex and not as the negative number the i32 is.
impl Debug for NtStatus
NtStatus(0xC0000005), in hex and not as the negative number the i32 is.