6 releases (3 breaking)

0.3.0 Jan 7, 2025
0.2.0 Jul 3, 2024
0.1.2 Jun 7, 2024
0.1.1 Apr 12, 2024
0.0.0 Feb 2, 2024

#122 in Windows APIs

Download history 460382/week @ 2024-10-08 496303/week @ 2024-10-15 488565/week @ 2024-10-22 526320/week @ 2024-10-29 623242/week @ 2024-11-05 650380/week @ 2024-11-12 646541/week @ 2024-11-19 554444/week @ 2024-11-26 652755/week @ 2024-12-03 751391/week @ 2024-12-10 651134/week @ 2024-12-17 344589/week @ 2024-12-24 470155/week @ 2024-12-31 895722/week @ 2025-01-07 955505/week @ 2025-01-14 747142/week @ 2025-01-21

3,146,902 downloads per month
Used in 8,317 crates (12 directly)

MIT/Apache

35KB
653 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(())
}

Dependencies

~0–8.5MB