microsoft / microsoft/windows-rs
`windows-bindgen` generated `_Impl` trait methods can be simplified
- Dominant language
- Rust
- Stars
- 12.8k
- Forks
- 665
- Avg merge
- 7h 9m
- Merged PRs (30d)
- 70
Description
### Suggestion
A COM interface whose methods are SAL annotated is usually simplified. However, the generated `_Impl` trait is less simplified.
For example, consider the following interface:
```c++
DEFINE_INTERFACE(ITestInterface, "7E17AD3C-47AF-4A71-85BD-1122EAB7E794") : public IUnknown
{
STDMETHOD_(HRESULT, EncryptBuffer)
(__in_bcount(cbSize) BYTE * pBuffer, _In_ size_t cbSize, _Out_ IBuffer * *ppvObj) = 0;
};
```
The generated `ITestInterface` looks like that:
```rust
impl ITestInterface {
pub unsafe fn EncryptBuffer(
&self,
pbuffer: &mut [u8],
) -> windows_core::Result {
// ...
}
}
```
`pBuffer` and `cbSize` were nicely merged into a mutable slice thanks to the SAL annotations. However, when implementing this interface we need to implement the following trait:
```rust
pub trait ITestInterface_Impl: Sized {
fn EncryptBuffer(
&self,
pbuffer: *mut u8,
cbsize: usize,
) -> windows_core::Result;
}
```
The return value for the `_Impl` trait method was simplified, but not the slice param. If it was simplified as well, it would allow us to implement the interface without using unsafe code
Contributor guide
Research direction
Start at the windows-bindgen generation path for `_Impl` traits and compare it with the existing SAL-based simplification used for interface methods. Update the generated trait signature so slice parameters are simplified consistently, then verify the example can be implemented without unsafe code and add or run the relevant generator tests if present.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100