Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid Result transformation for WIN32_ERROR #2890

Merged
merged 2 commits into from
Feb 27, 2024
Merged

Avoid Result transformation for WIN32_ERROR #2890

merged 2 commits into from
Feb 27, 2024

Conversation

kennykerr
Copy link
Collaborator

Much like NTSTATUS and RPC_STATUS, functions that return WIN32_ERROR often require the caller to inspect and branch based on the specific error code. Automatically transforming to a Result can make this needlessly complicated as the error code needs to be re-translated back from an HRESULT.

Callers that still want a Result or ? error propagation can simply use the ok helper as in SomeApi().ok()?.

@kennykerr kennykerr merged commit cf65494 into master Feb 27, 2024
66 checks passed
@kennykerr kennykerr deleted the WIN32_ERROR branch February 27, 2024 16:38
@fgimian
Copy link

fgimian commented Feb 28, 2024

Is it worth marking WIN32_ERROR as #[must_use] @kennykerr? My only concern after upgrading to 0.54.0 is that it is now quite possible to forget to handle errors and no warnings are given about this (unlike previous versions which forced using Result values).

Cheers
Fotis

@kennykerr
Copy link
Collaborator Author

Good idea!

@fgimian
Copy link

fgimian commented Feb 28, 2024

Forgive me for a further question, but I notice various functions do still return Result types in 0.54.0, is this intentional? e.g. CloseHandle

Was this applied selectively to certain functions or should it be consistent throughout?

Thanks again mate, and keep up the great work!
Fotis

@kennykerr
Copy link
Collaborator Author

The transformation is (still) applied to functions that return HRESULT or BOOL, except under certain conditions where the original signature is preserved. In those cases, you're not really losing anything having it transformed into a Result.

@fgimian
Copy link

fgimian commented Feb 28, 2024

The transformation is (still) applied to functions that return HRESULT or BOOL, except under certain conditions where the original signature is preserved. In those cases, you're not really losing anything having it transformed into a Result.

Ah gotcha, that makes sense, thanks for the clarification 😄

dilawar added a commit to SubconsciousCompute/ndisapi-rs that referenced this pull request Mar 12, 2024
wiresock pushed a commit to wiresock/ndisapi-rs that referenced this pull request Mar 12, 2024
dilawar added a commit to SubconsciousCompute/ndisapi-rs that referenced this pull request Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants