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.
#571 originally suggested
AsRef<T>
, and was rejected as a lot of boilerplate to merely streamline niche use cases. This PR adds minimal code to allow "properly" handling something much less niche: COM smart pointers.Actually, there is! While the compiler will reject having two "potentially conflicting" impls of AsIUnknown if implemented in an exterior crate (on the basis that a future winapi version might add
impl Deref for IUnknown
), we can add such traits to winapi itself just fine without conflict. This PR would allow writing a ComPtr that rejects types like ID3D12FunctionReflection:This would help avoid some nasty corner cases at compile time.
Future Directions
This alone isn't enough to allow
wio::com::ComPtr::new
to be made safe, as there's nothing stopping you from implementing Deref returning a totally bogus/dangling IUnknown vtable in 100% safe rust:That could potentially be "fixed" by making one of the traits involved unsafe.
Option A: Breaking changes requiring winapi 0.4
Option B: 0.3-friendly "replacement" trait
Option C: 0.3-friendly Marker Trait
unsafe
anywhere (unless "interface" might be replaced with "unsafe interface"?)(@uuid $interface:ident $l:expr, $w1:expr, $w2:expr, $b1:expr, $b2:expr, $b3:expr, $b4:expr, $b5:expr, $b6:expr, $b7:expr, $b8:expr ) => ( + unsafe impl $crate::SoundInterface for $interface {} impl $crate::Interface for $interface {