microsoft / windows-rs

Rust for Windows
https://kennykerr.ca/rust-getting-started/
Apache License 2.0
10.23k stars 475 forks source link

Make enum variants associated constants on the enum type #3150

Closed farnoy closed 1 month ago

farnoy commented 1 month ago

Suggestion

Compare the generated enum like D3D12_BARRIER_SYNC with a similar enum generated by ash. Associated constants (and a richer bitflags API) make it easier to work with and less verbose.

You could then write code like this:

use D3D12_BARRIER_SYNC as B;
B::DRAW | B::COPY
kennykerr commented 1 month ago

This is controlled by the metadata definitions for such types. The code generator takes into account whether the original definitions were C-style enums or C++ enum classes and generates the bindings accordingly.

riverar commented 1 month ago

This type is currently marked as

[Flags]
public enum D3D12_BARRIER_SYNC
...

Is there something missing from metadata?

riverar commented 1 month ago

Ah this is a C enum, per DirectX headers

typedef enum D3D12_BARRIER_SYNC
{
    D3D12_BARRIER_SYNC_NONE                                                     = 0x0,
    D3D12_BARRIER_SYNC_ALL                                                      = 0x1,
    D3D12_BARRIER_SYNC_DRAW                                                     = 0x2,
    D3D12_BARRIER_SYNC_INDEX_INPUT                                              = 0x4,
...

Not sure there's anything we can do on the metadata side either, everything looks accurate. If you have a more specific enhancement you'd like to see, please create a new issue with more detail.