9 releases

new 0.3.4 May 19, 2025
0.3.2 Mar 18, 2025
0.2.0 Jul 3, 2024
0.1.0 Feb 22, 2024

#318 in Windows APIs

Download history 1003275/week @ 2025-01-30 1097181/week @ 2025-02-06 1059105/week @ 2025-02-13 1188544/week @ 2025-02-20 1300720/week @ 2025-02-27 1628660/week @ 2025-03-06 1862427/week @ 2025-03-13 3264031/week @ 2025-03-20 1734850/week @ 2025-03-27 1994930/week @ 2025-04-03 1850213/week @ 2025-04-10 1498343/week @ 2025-04-17 1612668/week @ 2025-04-24 1611868/week @ 2025-05-01 1779466/week @ 2025-05-08 1437787/week @ 2025-05-15

6,743,531 downloads per month
Used in 18,312 crates (20 directly)

MIT/Apache

35KB
711 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