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,
|
power_levels::RoomPowerLevelsEventContent,
|
||||||
},
|
},
|
||||||
AnyEphemeralRoomEvent, AnyOriginalMessageLikeEvent, AnyOriginalStateEvent,
|
AnyEphemeralRoomEvent, AnyOriginalMessageLikeEvent, AnyOriginalStateEvent,
|
||||||
AnyOriginalSyncMessageLikeEvent, AnyOriginalSyncStateEvent, AnyRoomEvent,
|
AnyOriginalSyncMessageLikeEvent, AnyOriginalSyncStateEvent, AnyRoomEvent, AnySyncRoomEvent,
|
||||||
AnyStateEventContent, AnySyncRoomEvent, EphemeralRoomEventType, GlobalAccountDataEventType,
|
EphemeralRoomEventType, GlobalAccountDataEventType, MessageLikeEventType,
|
||||||
MessageLikeEventType, MessageLikeUnsigned, OriginalMessageLikeEvent, OriginalStateEvent,
|
MessageLikeUnsigned, OriginalMessageLikeEvent, OriginalStateEvent,
|
||||||
OriginalSyncMessageLikeEvent, OriginalSyncStateEvent, RoomAccountDataEventType,
|
OriginalSyncMessageLikeEvent, OriginalSyncStateEvent, RoomAccountDataEventType,
|
||||||
StateEventType, ToDeviceEventType,
|
StateEventType, ToDeviceEventType,
|
||||||
},
|
},
|
||||||
@ -300,10 +300,8 @@ fn alias_event_field_access() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let deser = from_json_value::<AnyOriginalStateEvent>(json_data).unwrap();
|
let deser = from_json_value::<AnyOriginalStateEvent>(json_data).unwrap();
|
||||||
if let AnyStateEventContent::RoomAliases(RoomAliasesEventContent { aliases, .. }) =
|
if let AnyOriginalStateEvent::RoomAliases(ev) = &deser {
|
||||||
deser.content()
|
assert_eq!(ev.content.aliases, vec![room_alias_id!("#somewhere:localhost")])
|
||||||
{
|
|
||||||
assert_eq!(aliases, vec![room_alias_id!("#somewhere:localhost")])
|
|
||||||
} else {
|
} else {
|
||||||
panic!("the `Any*Event` enum's accessor methods may have been altered")
|
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::{
|
use super::{
|
||||||
event_parse::{EventEnumDecl, EventEnumEntry, EventKind, EventKindVariation},
|
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;
|
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 event_type_enum = format_ident!("{}Type", kind);
|
||||||
let self_variants: Vec<_> = variants.iter().map(|v| v.match_arm(quote! { Self })).collect();
|
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_enum = kind.to_content_enum();
|
||||||
let content_variants: Vec<_> = variants.iter().map(|v| v.ctor(&content_enum)).collect();
|
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! {
|
quote! {
|
||||||
/// Returns the content for this event.
|
/// Returns the content for this event.
|
||||||
pub fn content(&self) -> #content_enum {
|
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)
|
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> {
|
pub fn to_event_ident(self, var: EventKindVariation) -> syn::Result<Ident> {
|
||||||
use EventKindVariation as V;
|
use EventKindVariation as V;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user