Prefer optional over convertible parameters #3368
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Thanks to #3359, it's now a lot easier to reason about some of these more nuanced type scenarios. The
windows-bindgen
crate has traditionally overused theParam
trait to provide cover for various weird Windows API-isms but theParam
trait tends to be quite confusing when you don't get the parameters just right and in particular for APIs that don't expect polymorphism. In some cases its necessary - specifically for COM or WinRT polymorphism - but in particular it was previously used for all Win32 handle types which was almost always unnecessary.This update does two things:
Param
trait for handle typesOption<T>
for copyable parameter typesWhen combined this limits the fallout from the first and generally makes the API surface more coherent as optional parameters are actually optional and the vast majority of handle types, which aren't convertible, are simple type parameters.
In some cases where "handle polymorphism" is actually expected by some API you can simply use the
Into
orFrom
traits to perform the conversion.Fixes: #3320