7 unstable releases (3 breaking)

0.3.1 Feb 21, 2025
0.3.0 Jan 7, 2025
0.2.0 Jul 3, 2024
0.1.2 Jun 7, 2024
0.0.0 Feb 2, 2024

#275 in Windows APIs

Download history 626325/week @ 2024-11-21 576335/week @ 2024-11-28 681752/week @ 2024-12-05 747337/week @ 2024-12-12 459703/week @ 2024-12-19 351234/week @ 2024-12-26 660205/week @ 2025-01-02 997036/week @ 2025-01-09 897675/week @ 2025-01-16 920953/week @ 2025-01-23 1003275/week @ 2025-01-30 1097181/week @ 2025-02-06 1059105/week @ 2025-02-13 1188544/week @ 2025-02-20 1301149/week @ 2025-02-27 1632441/week @ 2025-03-06

5,424,035 downloads per month
Used in 9,499 crates (14 directly)

MIT/Apache

36KB
716 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