vk_generator

Struct GenConfig

Source
pub struct GenConfig<'a> {
Show 15 fields pub remove_type_prefix: bool, pub remove_vk_result_prefix: bool, pub remove_command_prefix: bool, pub remove_bitmask_prefix: bool, pub remove_const_prefix: bool, pub variant_padding: VariantPaddingConfig, pub snake_case_commands: bool, pub camel_case_variants: bool, pub snake_case_members: bool, pub debug_c_strings: bool, pub use_native_enums: bool, pub use_native_unions: bool, pub wrap_bitmasks: bool, pub use_libc_types: bool, pub extern_type_overrides: &'a [(&'a str, &'a str)],
}
Expand description

Configuration options fot the Vulkan generator.

Fields§

§remove_type_prefix: bool

Whether or not to remove the Vk prefix on structs, enums, and typedefs.

As an example, take the struct VkInstanceCreateInfo. If this is set to true, the generator will turn that into InstanceCreateInfo.

Defaults to false.

§remove_vk_result_prefix: bool

Whether or not to remove the Vk prefix from the VkResult enum, IF AND ONLY IF remove_type_prefix is also set to true. This flag exists primarily because Rust already contains a type named Result and one might desire to remove any ambiguity the VkResult type may cause.

Defaults to true.

§remove_command_prefix: bool

Whether or not to remove the vk prefix from Vulkan commands.

For example, if we have the command vkCreateInstance setting this flag to true will turn that into createInstance.

Defaults to true.

§remove_bitmask_prefix: bool

Whether or not to remove the VK_ prefix from bitmask variants.

For example, the xml registry defines the bitmask VkQueueFlagBits with the flag VK_QUEUE_GRAPHICS_BIT. If this is true, this will result in the variant being turned into QUEUE_GRAPHICS_BIT.

Defaults to true.

§remove_const_prefix: bool

Whether or not to remove the VK_ prefix from constant names.

For example, the xml registry defines the constant VK_MAX_EXTENSION_NAME_SIZE. If this is true, this will result in the constant being turned into MAX_EXTENSION_NAME_SIZE.

Defaults to true.

§variant_padding: VariantPaddingConfig

How to handle enum variants, see VariantPaddingConfig for details.

Defaults to VariantPaddingConfig::Strip.

§snake_case_commands: bool

Whether or not to transform Vulkan command identifiers to be a Rust-y snake_case.

For example, the registry defines the command vkCreateInstance. If this is true, that command will be turned into vk_create_instance. This, and the other name-style-altering options, primarily exists for the purpose of having Vulkan code integrate more cleanly into native Rust code.

Defaults to true.

§camel_case_variants: bool

Whether or not to transform enum variants into CamelCase.

For example, if we look at VkStructureType’s VK_STRUCTURE_TYPE_APPLICATION_INFO setting this to true would result in the variant being turned into VkStructureTypeApplicationInfo.

Defaults to true.

§snake_case_members: bool

Whether or not to transform struct/union members and command parameters into snake_case.

For example, if we look at the VkApplicationInfo struct’s applicationVersion field, setting this to true would result in the field being turned into application_version.

Defaults to true.

§debug_c_strings: bool

When printing structs with fields that are arrays of c_chars, whether to print them as arrays of bytes or as a string.

Defaults to true.

§use_native_enums: bool

Whether or not to use the enum keyword to create native tagged unions.

Defaults to true.

§use_native_unions: bool

Whether or not to use the unstable union keyword to create native untagged unions. Currently relies on the untagged_unions feature.

Defaults to false.

§wrap_bitmasks: bool

Whether or not to wrap bitmasks with a set of convenience functions similar to the bitflags crate.

Defaults to true.

§use_libc_types: bool

The Vulkan library uses a lot of C types, as per it’s nature of exposing a C ABI. There are a few ways we can handle using those types: either we can define the typedefs ourself or we can use the types provided by libc. Because libc isn’t implicitly included in crates we default to defining the types ourself. Setting this to true makes the generated file import types from libc instead of defining them itself.

§extern_type_overrides: &'a [(&'a str, &'a str)]

This defines a set of type overrides, primarily intended for use with the WSI extensions. It takes a slice of (&str, &str) tuples, with the left side being the name of the type and the right side being the new definition of the type.

For an example let’s look at the Windows WSI extension, which includes the struct VkWin32SurfaceCreateInfoKHR. That struct takes a HWND and a HINSTANCE in order to let Vulkan draw to windows; however, the generator is unaware of both HWND and HINSTANCE, which are defined in winapi. Because it has no idea what those types should be the generator defaults to type HWND = *const (), which isn’t what HWNDs are defined as in winapi. So we call this:

let config = GenConfig {
    extern_type_overrides: &[
        ("HWND", "winapi::HWND"),
        ("HINSTANCE", "winapi::HINSTANCE")
    ],
    ..GenConfig::default()
};

This tells the generator to use the winapi defintions of HWND instead of the blind definition, making the generator produce these for the type defintions:

type HWND = winapi::HWND;
type HINSTANCE = winapi::HINSTANCE;

Implementations§

Source§

impl<'a> GenConfig<'a>

Source

pub fn new() -> Self

Create a new generator config. Is identical to Default::default().

Trait Implementations§

Source§

impl<'a> Clone for GenConfig<'a>

Source§

fn clone(&self) -> GenConfig<'a>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for GenConfig<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Default for GenConfig<'a>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'a> PartialEq for GenConfig<'a>

Source§

fn eq(&self, other: &GenConfig<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> Copy for GenConfig<'a>

Source§

impl<'a> Eq for GenConfig<'a>

Source§

impl<'a> StructuralPartialEq for GenConfig<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for GenConfig<'a>

§

impl<'a> RefUnwindSafe for GenConfig<'a>

§

impl<'a> Send for GenConfig<'a>

§

impl<'a> Sync for GenConfig<'a>

§

impl<'a> Unpin for GenConfig<'a>

§

impl<'a> UnwindSafe for GenConfig<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.