events: Remove some accessor functions
They will no longer make sense with the new enum hierarchy.
This commit is contained in:
parent
51244d5ae7
commit
f540bbbc99
@ -11,9 +11,9 @@ use ruma_common::{
|
||||
power_levels::RoomPowerLevelsEventContent,
|
||||
},
|
||||
AnyEphemeralRoomEvent, AnyOriginalMessageLikeEvent, AnyOriginalStateEvent,
|
||||
AnyOriginalSyncMessageLikeEvent, AnyOriginalSyncStateEvent, AnyRoomEvent,
|
||||
AnyStateEventContent, AnySyncRoomEvent, EphemeralRoomEventType, GlobalAccountDataEventType,
|
||||
MessageLikeEventType, MessageLikeUnsigned, OriginalMessageLikeEvent, OriginalStateEvent,
|
||||
AnyOriginalSyncMessageLikeEvent, AnyOriginalSyncStateEvent, AnyRoomEvent, AnySyncRoomEvent,
|
||||
EphemeralRoomEventType, GlobalAccountDataEventType, MessageLikeEventType,
|
||||
MessageLikeUnsigned, OriginalMessageLikeEvent, OriginalStateEvent,
|
||||
OriginalSyncMessageLikeEvent, OriginalSyncStateEvent, RoomAccountDataEventType,
|
||||
StateEventType, ToDeviceEventType,
|
||||
},
|
||||
@ -300,10 +300,8 @@ fn alias_event_field_access() {
|
||||
);
|
||||
|
||||
let deser = from_json_value::<AnyOriginalStateEvent>(json_data).unwrap();
|
||||
if let AnyStateEventContent::RoomAliases(RoomAliasesEventContent { aliases, .. }) =
|
||||
deser.content()
|
||||
{
|
||||
assert_eq!(aliases, vec![room_alias_id!("#somewhere:localhost")])
|
||||
if let AnyOriginalStateEvent::RoomAliases(ev) = &deser {
|
||||
assert_eq!(ev.content.aliases, vec![room_alias_id!("#somewhere:localhost")])
|
||||
} else {
|
||||
panic!("the `Any*Event` enum's accessor methods may have been altered")
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ 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},
|
||||
util::is_non_stripped_room_event,
|
||||
};
|
||||
use crate::util::m_prefix_name_to_type_name;
|
||||
|
||||
@ -443,53 +443,10 @@ fn expand_accessor_methods(
|
||||
let event_type_enum = format_ident!("{}Type", kind);
|
||||
let self_variants: Vec<_> = variants.iter().map(|v| v.match_arm(quote! { Self })).collect();
|
||||
|
||||
let content_accessors = (!var.is_redacted()).then(|| {
|
||||
let content_accessors = (!kind.is_room()).then(|| {
|
||||
let content_enum = kind.to_content_enum();
|
||||
let content_variants: Vec<_> = variants.iter().map(|v| v.ctor(&content_enum)).collect();
|
||||
|
||||
let unsigned = if has_prev_content(kind, var) {
|
||||
quote! {
|
||||
/// Returns this event's unsigned field.
|
||||
pub fn unsigned(&self) -> #ruma_common::events::StateUnsigned<#content_enum> {
|
||||
match self {
|
||||
#(
|
||||
#self_variants(event) => {
|
||||
event.unsigned._map_prev_content(|c| {
|
||||
#content_variants(c.clone())
|
||||
})
|
||||
},
|
||||
)*
|
||||
Self::_Custom(event) => {
|
||||
event.unsigned._map_prev_content(|c| #content_enum::_Custom {
|
||||
event_type: crate::PrivOwnedStr(
|
||||
::std::convert::From::from(
|
||||
::std::string::ToString::to_string(
|
||||
&#ruma_common::events::EventContent::event_type(c)
|
||||
)
|
||||
),
|
||||
),
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if is_non_stripped_room_event(kind, var) {
|
||||
let field_type = field_return_type("unsigned", var, ruma_common);
|
||||
let variants = variants.iter().map(|v| v.match_arm(quote! { Self }));
|
||||
|
||||
quote! {
|
||||
/// Returns this event's unsigned field.
|
||||
pub fn unsigned(&self) -> &#field_type {
|
||||
match self {
|
||||
#( #variants(event) => &event.unsigned, )*
|
||||
Self::_Custom(event) => &event.unsigned,
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
quote! {}
|
||||
};
|
||||
|
||||
quote! {
|
||||
/// Returns the content for this event.
|
||||
pub fn content(&self) -> #content_enum {
|
||||
@ -506,8 +463,6 @@ fn expand_accessor_methods(
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
#unsigned
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -127,6 +127,10 @@ impl EventKind {
|
||||
matches!(self, Self::GlobalAccountData | Self::RoomAccountData)
|
||||
}
|
||||
|
||||
pub fn is_room(self) -> bool {
|
||||
matches!(self, Self::MessageLike | Self::RoomRedaction | Self::State)
|
||||
}
|
||||
|
||||
pub fn to_event_ident(self, var: EventKindVariation) -> syn::Result<Ident> {
|
||||
use EventKindVariation as V;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user