8 unstable releases (3 breaking)

0.3.2 Mar 18, 2025
0.3.1 Feb 21, 2025
0.3.0 Jan 7, 2025
0.2.0 Jul 3, 2024
0.0.0 Feb 2, 2024

#283 in Windows APIs

Download history 728993/week @ 2024-12-14 320553/week @ 2024-12-21 441724/week @ 2024-12-28 782955/week @ 2025-01-04 1020857/week @ 2025-01-11 865643/week @ 2025-01-18 951597/week @ 2025-01-25 1015459/week @ 2025-02-01 1152546/week @ 2025-02-08 1058036/week @ 2025-02-15 1186172/week @ 2025-02-22 1523982/week @ 2025-03-01 1600097/week @ 2025-03-08 2232627/week @ 2025-03-15 2883805/week @ 2025-03-22 1502208/week @ 2025-03-29

8,504,721 downloads per month
Used in 17,206 crates (18 directly)

MIT/Apache

35KB
714 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.3"

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