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

Handle duplicated enum variants in the protocol #621

Open
kchibisov opened this issue May 3, 2023 · 2 comments
Open

Handle duplicated enum variants in the protocol #621

kchibisov opened this issue May 3, 2023 · 2 comments

Comments

@kchibisov
Copy link
Member

kchibisov commented May 3, 2023

The enum in the wayland protocol could have duplicated items, advertising only different names.

Right now wayland scanner is not handling them, but I don't think there's a protocol in the wild using such a thing, so it's not an issue now, but it could be with the upcoming color management protocols.

The solution is simple and non-breaking, you should do something like:

#[repr(u32)]
#[derive(PartialEq, Eq)]
enum Foo {
  X = 1,
  B = 2,
}

impl Foo {
    // TODO: The same values should go into the `impl`.
    //
    // This is what should be emitted from the wayland-scanner.
    pub const C: Foo = Self::B;
}

fn main() {
    let z = Foo::C;
    match z {
        Foo::C => {}
        Foo::B => {}
        Foo::X => {}
    }
    println!("{}", Foo::X as u32);
}
@i509VCB
Copy link
Member

i509VCB commented May 4, 2023

One thing to consider (which sadly would be less ergonomic) would be to do enums like ash.

Another question, with the idea you proposed how do you determine which value name should be the variant name and which ones are associated constants?

fn main() {
    let z = Foo::C;
    match z {
        Foo::C => {}
        Foo::B => {}
        Foo::X => {}
    }
    println!("{}", Foo::X as u32);
}

This would lint in rustc since you'd have a redundant match statement branch.

@kchibisov
Copy link
Member Author

@i509VCB by order? Since the goal simply to include all of them in some way. The point is not in matching in the first place, but having a value. The thing is that arbitrary wayland enum can look like that and what I propose is non-breaking change.

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

2 participants