Files
tubestation/third_party/rust/windows-result/readme.md
Jim Blandy 4d7ca2a448 Bug 1910150: Update windows-rs to 0.58. r=glandium,supply-chain-reviewers
Update the `windows` Microsoft Windows binding crate to 0.58.

- Update `taskcluster/kinds/fetch/toolchains.yml` to request version
  0.58 of the `windows` crate.
- Update `build/rust/windows/Cargo.toml` to present itself as 0.58.
- Vendor the following new crates into `third_party/rust`:
    - windows-core
    - windows-implement
    - windows-interface
    - windows-result
    - windows-strings
- Update `supply-chain/imports.lock` as necessary.

Differential Revision: https://phabricator.services.mozilla.com/D218694
2024-08-07 16:00:47 +00:00

958 B

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(())
}