Add an equivalent to `MAKE_HRESULT`
Author: PaulDanceCreated Sep 21, 2026Updated Sep 21, 2026
Labelsenhancement
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.
Source: microsoft/windows-rs