Add an equivalent to `MAKE_HRESULT`

Open Beginner friendly
#4,979 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
rust

Research direction

Start by locating the HRESULT new-type and its existing constructors or methods in the repository. Check how public APIs are tested, then add a const-compatible equivalent for MAKE_HRESULT and determine whether the requested component accessors belong in the same change. Done means the helper and any accessors match the Windows macro behavior and have coverage for representative components.

Written by the indexing model from the issue text.

Description

enhancement
Suggestion

Sometimes, APIs provide some errors defined using the MAKE_HRESULT C macro. Although it is quite simple, when translating such APIs to Rust bindings, there is no equivalent provided here as far as I can tell. It would therefore be nice to include a small helper towards that, if possible compatible with const contexts.

I would see it as an associated function on the HRESULT new-type, for example:

impl HRESULT {
    const fn from_components(severity: u32, facility: u32, code: u32) -> Self {
        Self(((severity << 31) | (facility << 16) | code) as _)
    }
}

It could also be nice to add accessors to these components as well in order to get equivalents of the HRESULT_SEVERITY, HRESULT_FACILITY, and HRESULT_CODE macros too.

Dominant language
Rust
Stars
12.8k
Forks
665
Avg merge
7h 9m
Merged PRs (30d)
70

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/windows-rs

All issues in microsoft/windows-rs

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.