3 unstable releases

new 0.1.1 Apr 12, 2024
0.1.0 Feb 22, 2024
0.0.0 Feb 2, 2024

#190 in Windows APIs

Download history 634/week @ 2024-02-17 11482/week @ 2024-02-24 20747/week @ 2024-03-02 22669/week @ 2024-03-09 24097/week @ 2024-03-16 26082/week @ 2024-03-23 27642/week @ 2024-03-30 26058/week @ 2024-04-06

107,287 downloads per month
Used in 738 crates (2 directly)

MIT/Apache

25KB
511 lines

Windows error handling

The windows-result crate provides efficient Windows error handling and propagation with support for Win32, COM, and WinRT APIs.

Start by adding the following to your Cargo.toml file:

[dependencies.windows-result]
version = "0.1"

Use the HRESULT, Error, and specialized Result types as needed:

use windows_result::*;

const S_OK: HRESULT = HRESULT(0);
const ERROR_CANCELLED: u32 = 1223;
const E_CANCELLED: HRESULT = HRESULT::from_win32(ERROR_CANCELLED);

fn main() -> Result<()> {
    S_OK.ok()?;
    let e = Error::new(E_CANCELLED, "test message");
    assert_eq!(e.code(), E_CANCELLED);
    assert_eq!(e.message(), "test message");
    Ok(())
}

Dependencies

~0–6MB