Skip to content

Refactor the input parsing of event_enums!#121

Merged
jplatte merged 12 commits intoruma:masterfrom
DevinR528:refactor-event-macros
Jul 13, 2020
Merged

Refactor the input parsing of event_enums!#121
jplatte merged 12 commits intoruma:masterfrom
DevinR528:refactor-event-macros

Conversation

@DevinR528
Copy link
Copy Markdown
Member

Rename name -> kind and parse input as EventKind. EventKind will only parse for valid event kinds to guard against bad input.

Rename name -> kind and parse input as EventKind. EventKind will only
parse for valid event kinds to guard against bad input.
Comment thread ruma-events-macros/src/event_enum.rs Outdated
Comment thread ruma-events-macros/src/event_enum.rs Outdated
Comment thread ruma-events-macros/src/event_enum.rs Outdated
Comment thread ruma-events-macros/src/event_enum.rs Outdated
Comment thread ruma-events-macros/src/event_enum.rs Outdated
@DevinR528
Copy link
Copy Markdown
Member Author

I'm still kinda hoping to get rid of the string checks in the "helper" functions (like in accessor_methods). I'll look it over in the morning and comment again either way (if I figure something out or not).

Comment thread ruma-events-macros/src/event_enum.rs Outdated
Comment thread ruma-events-macros/src/event_enum.rs Outdated
Comment thread ruma-events-macros/src/event_enum.rs Outdated
Comment thread ruma-events-macros/src/event_enum.rs Outdated
@DevinR528
Copy link
Copy Markdown
Member Author

DevinR528 commented Jul 12, 2020

I'll check moving variants, I think that would work good! Should have a commit for it in a few hours.

Comment thread ruma-events-macros/src/event_enum.rs
Comment thread ruma-events-macros/src/event_enum.rs Outdated
Comment thread ruma-events-macros/src/event_enum.rs Outdated
Comment thread ruma-events-macros/src/event_enum.rs Outdated
Comment thread ruma-events-macros/src/event_enum.rs Outdated
Comment thread ruma-events-macros/src/event_enum.rs Outdated
}

const PREV_CONTENT_KIND: &[&str] = &[ANY_STATE_EVENT, ANY_SYNC_STATE_EVENT];
fn state_key_kind(name: &EventKind, _var: &EventKindVariation) -> bool {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You could inline a bunch of these that are only used once, as closures. (or is there some specific reason you didn't?)

Copy link
Copy Markdown
Member Author

@DevinR528 DevinR528 Jul 13, 2020

Choose a reason for hiding this comment

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

Size and readability but now I think they may be sort enough. I'll commit what I have then inline them so we have a before and after.

@jplatte
Copy link
Copy Markdown
Member

jplatte commented Jul 13, 2020

Just verified that room_event_kind and event_id_kind should be the same, and the previous arrays for those were also identical (modulo order).

Comment thread ruma-events-macros/src/event_enum.rs Outdated
Comment thread ruma-events-macros/src/event_enum.rs Outdated
Comment thread ruma-events-macros/src/event_enum.rs Outdated
@jplatte jplatte merged commit 1db4898 into ruma:master Jul 13, 2020
@DevinR528 DevinR528 deleted the refactor-event-macros branch May 3, 2021 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants