5 unstable releases

0.2.0 Jul 3, 2024
0.1.2 Jun 7, 2024
0.1.1 Apr 12, 2024
0.1.0 Feb 22, 2024
0.0.0 Feb 2, 2024

#168 in Windows APIs

Download history 107664/week @ 2024-07-19 121084/week @ 2024-07-26 124672/week @ 2024-08-02 153060/week @ 2024-08-09 222512/week @ 2024-08-16 341268/week @ 2024-08-23 338388/week @ 2024-08-30 365211/week @ 2024-09-06 352576/week @ 2024-09-13 418372/week @ 2024-09-20 447954/week @ 2024-09-27 468569/week @ 2024-10-04 469111/week @ 2024-10-11 497080/week @ 2024-10-18 481890/week @ 2024-10-25 497388/week @ 2024-11-01

2,026,999 downloads per month
Used in 6,314 crates (8 directly)

MIT/Apache

31KB
641 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.2"

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(())
}

lib.rs:

Learn more about Rust for Windows here: https://github.com/microsoft/windows-rs

Dependencies

~0–4.5MB