Skip to content

Add packed struct encoding#24

Merged
mitchellh merged 1 commit intomitchellh:mainfrom
by-nir:packed-struct
Jul 13, 2025
Merged

Add packed struct encoding#24
mitchellh merged 1 commit intomitchellh:mainfrom
by-nir:packed-struct

Conversation

@Nirlah
Copy link
Contributor

@Nirlah Nirlah commented Jul 13, 2025

A NS_OPTIONS macro can be represented in Zig using a packed struct.
This PR add support for implicitly encoding such options structs as integers for use in blocks and methods.

For example, the following type is mapped into a packed struct in Zig.
It can than be used trivially as a method parameter.

typedef NS_OPTIONS(NSUInteger, NSApplicationPresentationOptions) {
    NSApplicationPresentationDefault = 0,
    NSApplicationPresentationAutoHideDock = (1 <<  0),
    // ...
    NSApplicationPresentationDisableCursorLocationAssistance API_AVAILABLE(macos(10.11.2)) = (1 << 12)
}
pub const NSApplicationPresentationOptions = packed struct(c_ulonglong) {
    auto_hide_dock: bool = false,
    // ...
    disable_cursor_location_assistance: bool = false,
    _: u51 = 0,

    pub const default: @This() = .{};
};

Implicitly encode packed struct as their backing integer.
@mitchellh mitchellh merged commit 27e3657 into mitchellh:main Jul 13, 2025
1 check passed
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

Successfully merging this pull request may close these issues.

2 participants