Consider improving accessibility of working with flexible array members in the windows
crate
#3172
Labels
question
Further information is requested
windows
crate
#3172
Suggestion
Many Windows APIs return flexible array members. Working with them in Rust is terrible. You must only use raw pointers, as references will invalidate access to the undeclared part of the array in Stacked Borrows (rust-lang/unsafe-code-guidelines#256), and it's easy to make mistakes and cause UB.
We can generate a simple wrapper type per FAM that can simplify working with them a lot. Something along the lines of:
There can be additional extensions (for example, supporting taking mutable references to many array members at the same time, safely allocating FAMs on the stack or the heap, or freeing them automatically) but even that alone is way better than the status quo.
Every function taking a pointer to a flexible struct will gain the ability to call it with its wrapper instead (probably with a trait).
I don't know if win32metadata marks flexible array members and their length field, so I don't know if this is possible, but if it is it can be a major improvement.
The text was updated successfully, but these errors were encountered: