Osspial / vk-rs

Collection of Rust libraries for the Vulkan API
MIT License
24 stars 4 forks source link

Generating numerical constants instead of enum variants #8

Closed kvark closed 6 years ago

kvark commented 6 years ago

How easy would this option be to implement? I need:

pub const SYSTEM_ALLOCATION_SCOPE_COMMAND: u32 = 0;
pub const SYSTEM_ALLOCATION_SCOPE_OBJECT:u32 = 1;
pub const SYSTEM_ALLOCATION_SCOPE_CACHE:u32 = 2;
pub const SYSTEM_ALLOCATION_SCOPE_DEVICE:u32 = 3;
pub const SYSTEM_ALLOCATION_SCOPE_INSTANCE:u32 = 4;
}

instead of

pub enum SystemAllocationScope {
    VK_SYSTEM_ALLOCATION_SCOPE_COMMAND = 0,
    VK_SYSTEM_ALLOCATION_SCOPE_OBJECT = 1,
    VK_SYSTEM_ALLOCATION_SCOPE_CACHE = 2,
    VK_SYSTEM_ALLOCATION_SCOPE_DEVICE = 3,
    VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE = 4,
}

One thing is moving from enum variants to constants. Another is - stripping "VK_" prefix only, leaving the other padding (SYSTEM_ALLOCATION_SCOPE_). Finally, I suppose the enum type would then turn into pub type SystemAllocationScope = u32;

kvark commented 6 years ago

Hacked this in https://github.com/Osspial/vk-rs/compare/master...kvark:enum-const Please let me know if you'd like this upstreamed, and in what shape.

Osspial commented 6 years ago

Having this upstreamed would be great - I'm actually kinda surprised this wasn't implemented already. Most of the code in the hack looks good, but it would need a config flag to switch between the enum and numerical constants version. It might also make sense to make the enum type a wrapper struct to keep type-checking, which in this case would be pub struct SystemAllocationScope(u32);

Osspial commented 6 years ago

Getting enum stripping to only strip VK_ should be easy enough, but I'll look into doing that after I get some sleep and can actually think about code.