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

Put enum constants on the enum itself #580

Merged
merged 3 commits into from
Feb 9, 2024
Merged

Put enum constants on the enum itself #580

merged 3 commits into from
Feb 9, 2024

Conversation

madsmtm
Copy link
Owner

@madsmtm madsmtm commented Feb 7, 2024

This required two large rewrites of header-translator's internals, as emitting the correct Rust for a given enum constant was tricky, but now we're here!

This should help a lot with uncluttering the top-level namespace for each framework.

// Generated before
pub type AXHearingDeviceEar = NSInteger;
pub const AXHearingDeviceEarNone: AXHearingDeviceEar = 0;
pub const AXHearingDeviceEarLeft: AXHearingDeviceEar = 1 << 1;
pub const AXHearingDeviceEarRight: AXHearingDeviceEar = 1 << 2;
pub const AXHearingDeviceEarBoth: AXHearingDeviceEar = AXHearingDeviceEarLeft | AXHearingDeviceEarRight;

// Generated now
pub struct AXHearingDeviceEar(pub NSInteger);
impl AXHearingDeviceEar {
    #[doc(alias = "AXHearingDeviceEarNone")]
    pub const None: Self = Self(0);
    #[doc(alias = "AXHearingDeviceEarLeft")]
    pub const Left: Self = Self(1 << 1);
    #[doc(alias = "AXHearingDeviceEarRight")]
    pub const Right: Self = Self(1 << 2);
    #[doc(alias = "AXHearingDeviceEarBoth")]
    pub const Both: Self = Self(AXHearingDeviceEar::Left.0 | AXHearingDeviceEar::Right.0);
}

Part of #310, though more work here is definitely needed.

@madsmtm madsmtm added enhancement New feature or request A-framework Affects the framework crates and the translator for them labels Feb 7, 2024
@madsmtm madsmtm merged commit 89b1ed8 into master Feb 9, 2024
19 checks passed
@madsmtm madsmtm deleted the fix-enums branch February 9, 2024 01:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-framework Affects the framework crates and the translator for them enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant