Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@nicoburns
Copy link
Contributor

@waywardmonkeys
Copy link
Collaborator

Does this improve or simplify your usage in Blitz as well? Can you give a brief example so that we have a history of the motivation?

@nicoburns
Copy link
Contributor Author

I don't have ui-events integrated into Blitz yet. But this allows for two things:

  1. Accessing the fields with the . operator. This can sometimes be significantly more ergonomic than destructuring. Notably if you only want to access a single field.
  2. Passing the specific event to a function or method. Consider downstream code consuming PointerEvent. Likely there will be a handle_mouse_down method or similar. With the pre-existing design there is no type to pass to such a method (you would have to use a tuple or create your own type). With the new design you can pass a PointerButtonPressEvent (or reference to the same).

(2) is the more significant. However, an example of (1) with a different enum struct-variant from Dioxus:

With struct-variant:

fn map_template_attr(attr: &TemplateAttribute) -> Option<Attribute> {
    let TemplateAttribute::Static {
        name,
        value,
        namespace,
    } = attr
    else {
        return None;
    };

    let name = qual_name(name, *namespace);
    let value = value.to_string();
    Some(Attribute { name, value })
}

With actual struct inside tuple-variant:

fn map_template_attr(attr: &TemplateAttribute) -> Option<Attribute> {
    let TemplateAttribute::Static(attr) else {
        return None;
    };

    let name = qual_name(attr.name, *attr.namespace);
    let value = attr.value.to_string();
    Some(Attribute { name, value })
}

@nicoburns nicoburns force-pushed the eliminate-struct-enum-variants branch from a6fd121 to 0cc7663 Compare May 28, 2025 14:13
Copy link
Collaborator

@xorgy xorgy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good overall, setting aside the one nitpick and getting it rebased with the mutating tap counter change, I'm happy with it. :+ )
I personally don't prefer the separate structs, but if it is an easier API for others (and it seems widely preferred) then I'm fine with it.

@nicoburns nicoburns force-pushed the eliminate-struct-enum-variants branch from 0cc7663 to 9c3dd54 Compare May 30, 2025 13:44
@nicoburns nicoburns requested a review from xorgy May 30, 2025 13:44
Copy link
Collaborator

@waywardmonkeys waywardmonkeys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM apart from a copy/paste thing in a doc comment.

@nicoburns nicoburns force-pushed the eliminate-struct-enum-variants branch from 9c3dd54 to 65f2bd3 Compare May 31, 2025 21:06
@waywardmonkeys waywardmonkeys merged commit 8c54b96 into endoli:main Jun 1, 2025
19 checks 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.

Enum Struct Variants are Hard To Use

3 participants