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

Add Ord/PartialOrd/Hash/Eq derives to generated enums in rust side #7985

Open
qarmin opened this issue Mar 30, 2025 · 2 comments
Open

Add Ord/PartialOrd/Hash/Eq derives to generated enums in rust side #7985

qarmin opened this issue Mar 30, 2025 · 2 comments
Labels
a:language-rust Rust API and codegen (mO,mS) breaking change Anything that probably require a semver bump enhancement New feature or request

Comments

@qarmin
Copy link

qarmin commented Mar 30, 2025

Feature Description

Using

export enum CurrentTab {

generates this rust code

# [derive (Default , Copy , Clone , PartialEq , Debug)] pub enum r#CurrentTab {

I want to use CurrentTab in BTreeMap/HashMap as key, but currently I cannot do this, due missing traits, so I must manually implement them

impl Hash for CurrentTab {
    fn hash<H: Hasher>(&self, state: &mut H) {
        (*self as u8).hash(state);
    }
}
impl Eq for CurrentTab {}

Can this derives be added by default?

Product Impact

No response

@qarmin qarmin added enhancement New feature or request need triaging Issue that the owner of the area still need to triage labels Mar 30, 2025
@qarmin qarmin changed the title Add Ord/PartialOrd/Hash derives to generated enums in rust side Add Ord/PartialOrd/Hash/Eq derives to generated enums in rust side Mar 30, 2025
@tronical
Copy link
Member

I suppose adding them now would break existing code. But what you can do is to use @rust-attr(derive(Ord)) etc to let the compiler generate them. See the bottom of https://docs.slint.dev/latest/docs/rust/slint/docs/type_mappings/ for an example (with Serde).

@ogoffart ogoffart added a:language-rust Rust API and codegen (mO,mS) breaking change Anything that probably require a semver bump and removed need triaging Issue that the owner of the area still need to triage labels Mar 30, 2025
@ogoffart
Copy link
Member

This would be a breaking change if one already has implement it manually.
But we probably should add them if we go for a Slint 2.0 or some kind of edition system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:language-rust Rust API and codegen (mO,mS) breaking change Anything that probably require a semver bump enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants