get-last-error

Crates.ioget-last-error
lib.rsget-last-error
version0.1.1
sourcesrc
created_at2022-02-09 17:30:32.505114
updated_at2022-07-09 12:11:20.933962
descriptionAn error wrapper over Win32 API errors.
homepagehttps://github.com/OpenByteDev/get-last-error
repositoryhttps://github.com/OpenByteDev/get-last-error
max_upload_size
id529801
size13,222
OpenByte (OpenByteDev)

documentation

https://docs.rs/get-last-error

README

get-last-error

CI crates.io Documentation dependency status MIT

An error wrapper over Win32 API errors.

Examples

A Win32Error can be constructed from an arbitrary DWORD:

use get_last_error::Win32Error;

let err = Win32Error::new(0);
println!("{}", err); // prints "The operation completed successfully."

The Win32Error::get_last_error retrieves the last error code for the current thread:

use get_last_error::Win32Error;
use winapi::um::{winnt::HANDLE, processthreadsapi::OpenProcess};

fn open_process() -> Result<HANDLE, Win32Error> {
    let result = unsafe { OpenProcess(0, 0, 0) }; // some windows api call
    if result.is_null() { // null indicates failure.
        Err(Win32Error::get_last_error())
    } else {
        Ok(result)
    }
}

License

Licensed under MIT license (LICENSE or http://opensource.org/licenses/MIT)

Commit count: 9

cargo fmt