Skip to main content

NtStatus

Struct NtStatus 

Source
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

Source

pub const fn from_raw(raw: i32) -> Self

Wraps a raw NTSTATUS. Any value is accepted.

Source

pub const fn raw(self) -> i32

The raw NTSTATUS, unaltered.

Source

pub const fn severity(self) -> NtSeverity

The severity, from the top two bits.

Source

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.

Source

pub const fn is_information(self) -> bool

NT_INFORMATION: whether the severity is informational.

Source

pub const fn is_warning(self) -> bool

NT_WARNING: whether the severity is a warning.

Source

pub const fn is_error(self) -> bool

NT_ERROR: whether the severity is an error.

Source

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.

Source

pub const fn code(self) -> u16

The low 16 bits.

Source

pub const fn facility(self) -> u16

The twelve bits above the code.

Source

pub const fn is_customer(self) -> bool

Whether the customer bit is set: a code a third party defined, not Microsoft.

Trait Implementations§

Source§

impl Clone for NtStatus

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for NtStatus

Source§

impl Debug for NtStatus

NtStatus(0xC0000005), in hex and not as the negative number the i32 is.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for NtStatus

The value in hex, as ntstatus.h writes it: 0xC0000005.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for NtStatus

Source§

impl Hash for NtStatus

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for NtStatus

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for NtStatus

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.