Return owned value for origin_server_ts accessors

This commit is contained in:
Naman Sandilya 2022-04-27 16:00:24 +05:30 committed by GitHub
parent cc72ddb689
commit 0cdd6a7b0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 17 deletions

View File

@ -152,7 +152,7 @@ pub enum AnyRoomEvent {
}
impl AnyRoomEvent {
room_ev_accessor!(origin_server_ts: &MilliSecondsSinceUnixEpoch);
room_ev_accessor!(origin_server_ts: MilliSecondsSinceUnixEpoch);
room_ev_accessor!(room_id: &RoomId);
room_ev_accessor!(event_id: &EventId);
room_ev_accessor!(sender: &UserId);
@ -180,7 +180,7 @@ pub enum AnySyncRoomEvent {
}
impl AnySyncRoomEvent {
room_ev_accessor!(origin_server_ts: &MilliSecondsSinceUnixEpoch);
room_ev_accessor!(origin_server_ts: MilliSecondsSinceUnixEpoch);
room_ev_accessor!(event_id: &EventId);
room_ev_accessor!(sender: &UserId);

View File

@ -446,10 +446,10 @@ macro_rules! impl_possibly_redacted_event {
}
/// Returns this event's `origin_server_ts` field.
pub fn origin_server_ts(&self) -> &MilliSecondsSinceUnixEpoch {
pub fn origin_server_ts(&self) -> MilliSecondsSinceUnixEpoch {
match self {
Self::Original(ev) => &ev.origin_server_ts,
Self::Redacted(ev) => &ev.origin_server_ts,
Self::Original(ev) => ev.origin_server_ts,
Self::Redacted(ev) => ev.origin_server_ts,
}
}

View File

@ -216,10 +216,10 @@ impl RoomRedactionEvent {
}
/// Returns this event's `origin_server_ts` field.
pub fn origin_server_ts(&self) -> &MilliSecondsSinceUnixEpoch {
pub fn origin_server_ts(&self) -> MilliSecondsSinceUnixEpoch {
match self {
Self::Original(ev) => &ev.origin_server_ts,
Self::Redacted(ev) => &ev.origin_server_ts,
Self::Original(ev) => ev.origin_server_ts,
Self::Redacted(ev) => ev.origin_server_ts,
}
}
@ -293,10 +293,10 @@ impl SyncRoomRedactionEvent {
}
/// Returns this event's `origin_server_ts` field.
pub fn origin_server_ts(&self) -> &MilliSecondsSinceUnixEpoch {
pub fn origin_server_ts(&self) -> MilliSecondsSinceUnixEpoch {
match self {
Self::Original(ev) => &ev.origin_server_ts,
Self::Redacted(ev) => &ev.origin_server_ts,
Self::Original(ev) => ev.origin_server_ts,
Self::Redacted(ev) => ev.origin_server_ts,
}
}

View File

@ -470,13 +470,14 @@ fn expand_accessor_methods(
let field_type = field_return_type(name, ruma_common);
let variants = variants.iter().map(|v| v.match_arm(quote! { Self }));
let call_parens = maybe_redacted.then(|| quote! { () });
let ampersand = (*name != "origin_server_ts").then(|| quote! { & });
quote! {
#[doc = #docs]
pub fn #ident(&self) -> &#field_type {
pub fn #ident(&self) -> #field_type {
match self {
#( #variants(event) => &event.#ident #call_parens, )*
Self::_Custom(event) => &event.#ident #call_parens,
#( #variants(event) => #ampersand event.#ident #call_parens, )*
Self::_Custom(event) => #ampersand event.#ident #call_parens,
}
}
}
@ -584,9 +585,9 @@ fn event_module_path(name: &LitStr) -> Vec<Ident> {
fn field_return_type(name: &str, ruma_common: &TokenStream) -> TokenStream {
match name {
"origin_server_ts" => quote! { #ruma_common::MilliSecondsSinceUnixEpoch },
"room_id" => quote! { #ruma_common::RoomId },
"event_id" => quote! { #ruma_common::EventId },
"sender" => quote! { #ruma_common::UserId },
"room_id" => quote! { &#ruma_common::RoomId },
"event_id" => quote! { &#ruma_common::EventId },
"sender" => quote! { &#ruma_common::UserId },
_ => panic!("the `ruma_macros::event_enum::EVENT_FIELD` const was changed"),
}
}