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

#316 in Windows APIs

Download history 373248/week @ 2024-12-20 398871/week @ 2024-12-27 719801/week @ 2025-01-03 1024230/week @ 2025-01-10 877202/week @ 2025-01-17 935618/week @ 2025-01-24 1007561/week @ 2025-01-31 1124489/week @ 2025-02-07 1052593/week @ 2025-02-14 1200824/week @ 2025-02-21 1429226/week @ 2025-02-28 1592261/week @ 2025-03-07 1941668/week @ 2025-03-14 3184074/week @ 2025-03-21 1767721/week @ 2025-03-28 2011039/week @ 2025-04-04

9,222,448 downloads per month
Used in 17,404 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