Skip to main content

LStatus

Struct LStatus 

Source
pub struct LStatus(/* private fields */);
Expand description

A Win32 error code in a signed carrier: the LONG that LSTATUS is, which the registry calls (RegOpenKeyExW and the rest) return.

It is the same number space as Win32Error, and the registry’s own documentation calls the value an error code: zero is ERROR_SUCCESS and anything else is the code. It is a type of its own because it is the signed carrier, so a LONG is never read as a DWORD by accident, and the cast between the two is made once, here, and is a bit cast that loses nothing in either direction. A value is not assumed to be non-negative: a code above 2^31 is a negative LONG.

§Example

use win_error_codes::{LStatus, Win32Error};

// What a registry call returns for success, and for ERROR_FILE_NOT_FOUND.
assert_eq!(LStatus::from_raw(0).into_result(), Ok(()));
assert_eq!(
    LStatus::from_raw(2).into_result(),
    Err(Win32Error::from_code(2))
);

// The same number space, so the two convert both ways without loss, including a code that
// needs the sign bit.
let status = LStatus::from_raw(-1_069_940_715);
assert_eq!(status.to_win32(), Win32Error::from_code(0xC03A_0015));
assert_eq!(Win32Error::from_code(0xC03A_0015).to_lstatus(), status);

Implementations§

Source§

impl LStatus

Source

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

Wraps the raw LONG a call returned. Any value is accepted, zero included.

Source

pub const fn raw(self) -> i32

The raw LONG, unaltered.

Source

pub const fn is_success(self) -> bool

Whether this is ERROR_SUCCESS, which is zero.

Source

pub const fn into_result(self) -> Result<(), Win32Error>

Ok for ERROR_SUCCESS and Err carrying the code for anything else, which is how a call that returns an LSTATUS becomes a Result.

§Errors

The code, as a Win32Error, when it is not ERROR_SUCCESS.

Source

pub const fn to_win32(self) -> Win32Error

The same code as a Win32Error: a bit cast from i32 to u32, so a negative value is a code above 2^31 and not its magnitude.

Trait Implementations§

Source§

impl Clone for LStatus

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 LStatus

Source§

impl Debug for LStatus

Source§

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

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

impl Display for LStatus

The code as Win32Error shows it: there is no separate rendering for the signed carrier, since the two are the same number space.

Source§

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

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

impl Eq for LStatus

Source§

impl From<LStatus> for Win32Error

Source§

fn from(status: LStatus) -> Self

Converts to this type from the input type.
Source§

impl From<Win32Error> for LStatus

Source§

fn from(error: Win32Error) -> Self

Converts to this type from the input type.
Source§

impl Hash for LStatus

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 LStatus

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 LStatus

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.