3 unstable releases

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

#226 in Windows APIs

Download history 1239/week @ 2024-02-19 15072/week @ 2024-02-26 21033/week @ 2024-03-04 22344/week @ 2024-03-11 24865/week @ 2024-03-18 25924/week @ 2024-03-25 27885/week @ 2024-04-01 32849/week @ 2024-04-08 41006/week @ 2024-04-15 48377/week @ 2024-04-22 51260/week @ 2024-04-29 55421/week @ 2024-05-06

199,383 downloads per month
Used in 919 crates (3 directly)

MIT/Apache

24KB
504 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–4.5MB