From d599c7227854346ca4f8a75c1621bdaa67676ccc Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Thu, 27 Mar 2025 13:43:22 +0200 Subject: [PATCH] chore(ui): use a newer version of `as_variant` to match nested types. --- .../src/timeline/event_item/content/mod.rs | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/crates/matrix-sdk-ui/src/timeline/event_item/content/mod.rs b/crates/matrix-sdk-ui/src/timeline/event_item/content/mod.rs index 9cfa3a03e..61c1c4836 100644 --- a/crates/matrix-sdk-ui/src/timeline/event_item/content/mod.rs +++ b/crates/matrix-sdk-ui/src/timeline/event_item/content/mod.rs @@ -333,22 +333,29 @@ impl TimelineItemContent { /// If `self` is of the [`Aggregated`][Self::Aggregated] variant, return the /// inner [`Message`]. pub fn as_message(&self) -> Option<&Message> { - let aggregated = as_variant!(self, Self::Aggregated)?; - as_variant!(&aggregated.kind, AggregatedTimelineItemContentKind::Message) + as_variant!(self, Self::Aggregated(AggregatedTimelineItemContent { + kind: AggregatedTimelineItemContentKind::Message(message), + .. + }) => message) } /// If `self` is of the [`Aggregated`][Self::Aggregated] variant, return the /// inner [`PollState`]. pub fn as_poll(&self) -> Option<&PollState> { - let aggregated = as_variant!(self, Self::Aggregated)?; - as_variant!(&aggregated.kind, AggregatedTimelineItemContentKind::Poll) + as_variant!(self, Self::Aggregated(AggregatedTimelineItemContent { + kind: AggregatedTimelineItemContentKind::Poll(poll_state), + .. + }) => poll_state) } pub fn as_sticker(&self) -> Option<&Sticker> { - let aggregated = as_variant!(self, Self::Aggregated) - .map(|f| as_variant!(&f.kind, AggregatedTimelineItemContentKind::Sticker)); - - aggregated.unwrap_or(None) + as_variant!( + self, + Self::Aggregated(AggregatedTimelineItemContent { + kind: AggregatedTimelineItemContentKind::Sticker(sticker), + .. + }) => sticker + ) } /// If `self` is of the [`UnableToDecrypt`][Self::UnableToDecrypt] variant,