Is there something I can do to VkDescriptorSetLayout to remove that optional?
I can obviously just redefine VkDescriptorSetLayout without the optional, but I would have to do that for dozens and dozens of types in Vulkan. I’m hoping there is something clever I can do.
I’m not sure how helpful this is, as it depends somewhat on how you’re using the types, but you can unwrap, or “de-optional”, a value by using the orelse keyword. It works similarly to the catch keyword. For example the following code:
Generally you will only use such handles as arguments in Vulkan functions, which take an optional pointer as a parameter, so it’s not really necessary to remove the optional. If you’re worried about safety, I’m fairly confident your validation layers (if enabled) will check for null pointers anyway, so you shouldn’t need to yourself.
The issue is I’m slinging some of this stuff around in Zig arrays and tuples and having to “deoptional” everything at variable use is kind of a pest since I’ve already established that none of these things are null.
I didn’t think there was an obvious way to do this, but I thought I would ask.
comptime lets you cough up a lot of interesting manipulations on types and sometimes an action that you would think is complicated is surprisingly easy.
What’s wrong with slinging them around as optional pointers? There’s no cost to doing this. I’m curious why you would ever need to unwrap them, seeing as the underlying type is opaque.