Debian Codegraph @

third_party/rust/windows-result/readme.md

raw
1 ## Windows error handling
2
3 The [windows-result](https://crates.io/crates/windows-result) crate provides efficient Windows error handling and propagation with support for Win32, COM, and WinRT APIs.
4
5 * [Getting started](https://kennykerr.ca/rust-getting-started/)
6 * [Samples](https://github.com/microsoft/windows-rs/tree/0.58.0/crates/samples)
7 * [Releases](https://github.com/microsoft/windows-rs/releases)
8
9 Start by adding the following to your Cargo.toml file:
10
11 ```toml
12 [dependencies.windows-result]
13 version = "0.2"
14 ```
15
16 Use the `HRESULT`, `Error`, and specialized `Result` types as needed:
17
18 ```rust
19 use windows_result::*;
20
21 const S_OK: HRESULT = HRESULT(0);
22 const ERROR_CANCELLED: u32 = 1223;
23 const E_CANCELLED: HRESULT = HRESULT::from_win32(ERROR_CANCELLED);
24
25 fn main() -> Result<()> {
26 S_OK.ok()?;
27 let e = Error::new(E_CANCELLED, "test message");
28 assert_eq!(e.code(), E_CANCELLED);
29 assert_eq!(e.message(), "test message");
30 Ok(())
31 }
32 ```