From c787c8351e11e084cd653d52c3ed0fa4224e1355 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 24 Mar 2022 16:45:25 +0100 Subject: [PATCH] macros: Move EVENT_FIELDS out of util.rs It was only used by the event_enum! macro anyways. --- crates/ruma-macros/src/events/event_enum.rs | 22 ++++++++++++++++++++- crates/ruma-macros/src/events/util.rs | 20 ------------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/crates/ruma-macros/src/events/event_enum.rs b/crates/ruma-macros/src/events/event_enum.rs index 9492d70b..69cf8119 100644 --- a/crates/ruma-macros/src/events/event_enum.rs +++ b/crates/ruma-macros/src/events/event_enum.rs @@ -6,10 +6,30 @@ use syn::{Attribute, Data, DataEnum, DeriveInput, Ident, LitStr}; use super::{ event_parse::{EventEnumDecl, EventEnumEntry, EventKind, EventKindVariation}, - util::{has_prev_content, is_non_stripped_room_event, EVENT_FIELDS}, + util::{has_prev_content, is_non_stripped_room_event}, }; use crate::util::m_prefix_name_to_type_name; +type EventKindFn = fn(EventKind, EventKindVariation) -> bool; + +/// This const is used to generate the accessor methods for the `Any*Event` enums. +/// +/// DO NOT alter the field names unless the structs in `ruma_common::events::event_kinds` have +/// changed. +const EVENT_FIELDS: &[(&str, EventKindFn)] = &[ + ("origin_server_ts", is_non_stripped_room_event), + ("room_id", |kind, var| { + matches!(kind, EventKind::MessageLike | EventKind::State | EventKind::Ephemeral) + && matches!(var, EventKindVariation::Full | EventKindVariation::Redacted) + }), + ("event_id", is_non_stripped_room_event), + ("sender", |kind, var| { + matches!(kind, EventKind::MessageLike | EventKind::State | EventKind::ToDevice) + && var != EventKindVariation::Initial + }), + ("state_key", |kind, _| matches!(kind, EventKind::State)), +]; + /// Create a content enum from `EventEnumInput`. pub fn expand_event_enums(input: &EventEnumDecl) -> syn::Result { use EventKindVariation as V; diff --git a/crates/ruma-macros/src/events/util.rs b/crates/ruma-macros/src/events/util.rs index dd92f62f..d3d34843 100644 --- a/crates/ruma-macros/src/events/util.rs +++ b/crates/ruma-macros/src/events/util.rs @@ -15,23 +15,3 @@ pub(crate) fn has_prev_content(kind: EventKind, var: EventKindVariation) -> bool matches!(kind, EventKind::State) && matches!(var, EventKindVariation::Full | EventKindVariation::Sync) } - -pub(crate) type EventKindFn = fn(EventKind, EventKindVariation) -> bool; - -/// This const is used to generate the accessor methods for the `Any*Event` enums. -/// -/// DO NOT alter the field names unless the structs in `ruma_common::events::event_kinds` have -/// changed. -pub(crate) const EVENT_FIELDS: &[(&str, EventKindFn)] = &[ - ("origin_server_ts", is_non_stripped_room_event), - ("room_id", |kind, var| { - matches!(kind, EventKind::MessageLike | EventKind::State | EventKind::Ephemeral) - && matches!(var, EventKindVariation::Full | EventKindVariation::Redacted) - }), - ("event_id", is_non_stripped_room_event), - ("sender", |kind, var| { - matches!(kind, EventKind::MessageLike | EventKind::State | EventKind::ToDevice) - && var != EventKindVariation::Initial - }), - ("state_key", |kind, _| matches!(kind, EventKind::State)), -];