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

windows-bindgen should generate more specific Result<T, E> types #3294

Open
kennykerr opened this issue Sep 25, 2024 · 1 comment
Open

windows-bindgen should generate more specific Result<T, E> types #3294

kennykerr opened this issue Sep 25, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@kennykerr
Copy link
Collaborator

Rather than folding all error types into the windows_result::Error type, APIs can more specifically return Result<T, HRESULT>, Result<T, NTSTATUS>, and so on. This would avoid the overhead that necessitated #3126 and allow simple pattern matching for error handling. The reasoning around the Windows-specific Result<T, Error> is that it additionally carries any IErrorInfo that may have been associated with the calling thread. This turns out to be used by very few APIs but can still be supported as needed through conversion.

@kennykerr kennykerr added the enhancement New feature or request label Sep 25, 2024
@kennykerr
Copy link
Collaborator Author

One thing to keep in mind is that Result only really works well when there is one, or mostly one, success code. So it works fine for BOOL and it mostly works fine for HRESULT if you don't rely on nasty codes like S_FALSE but it doesn't work well for NTSTATUS in many cases because NTSTATUS has numerous codes, like STATUS_TIMEOUT, that are technically successful but in practice represent some kind of soft failure that would be lost if transformed into a Result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant