Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use opaque types instead of handle enums #115

Open
anyputer opened this issue Jan 11, 2024 · 2 comments
Open

Use opaque types instead of handle enums #115

anyputer opened this issue Jan 11, 2024 · 2 comments

Comments

@anyputer
Copy link

Instead of the following generated code:

pub const Instance = enum(usize) { null_handle = 0, _ };

we can make use of opaque types:

pub const Instance = opaque {}; // maybe *opaque {}?

This improves type safety with explicit nullability in generated code, and makes it easier to use with other C APIs that expect an opaque pointer. For example the instance argument in destroyInstance is not obviously nullable until you read the Vulkan spec, and null is obviously cleaner than .null_handle. This seems like a missed opportunity.

@Snektron
Copy link
Owner

Indeed, these were not a thing when vulkan-zig was initially made. Seems like a good idea, though there will be a slight incompatibility between dispatchable and non-dispatchable handles. I don't think that is much of a problem, though.

@Snektron Snektron added this to the Spring cleaning 2024 milestone Apr 26, 2024
@VoilaNeighbor
Copy link

For most of the times it's not a problem. Just when interfacing with other C libraries we have to do this:

@ptrFromInt(@intFromEnum(handle))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants