diff --git a/Cargo.lock b/Cargo.lock index 563feb55b..ba85e4883 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -200,9 +200,9 @@ dependencies = [ [[package]] name = "as_variant" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f38fa22307249f86fb7fad906fcae77f2564caeb56d7209103c551cd1cf4798f" +checksum = "9dbc3a507a82b17ba0d98f6ce8fd6954ea0c8152e98009d36a40d8dcc8ce078a" [[package]] name = "askama" diff --git a/Cargo.toml b/Cargo.toml index ed28f2191..1661c0611 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ assert_matches2 = "0.1.2" async-rx = "0.1.3" async-stream = "0.3.5" async-trait = "0.1.85" -as_variant = "1.2.0" +as_variant = "1.3.0" base64 = "0.22.1" byteorder = "1.5.0" chrono = "0.4.39" 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 ba17e1ca4..c708bd129 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,19 +333,15 @@ 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) - .map(|f| as_variant!(&f.kind, AggregatedTimelineItemContentKind::Message)); - - aggregated.unwrap_or(None) + let aggregated = as_variant!(self, Self::Aggregated)?; + as_variant!(&aggregated.kind, AggregatedTimelineItemContentKind::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) - .map(|f| as_variant!(&f.kind, AggregatedTimelineItemContentKind::Poll)); - - aggregated.unwrap_or(None) + let aggregated = as_variant!(self, Self::Aggregated)?; + as_variant!(&aggregated.kind, AggregatedTimelineItemContentKind::Poll) } /// If `self` is of the [`UnableToDecrypt`][Self::UnableToDecrypt] variant, @@ -509,12 +505,12 @@ impl TimelineItemContent { /// Event ID of the thread root, if this is a threaded message. pub fn thread_root(&self) -> Option { - as_variant!(self, TimelineItemContent::Aggregated).and_then(|agg| agg.thread_root.clone()) + as_variant!(self, Self::Aggregated)?.thread_root.clone() } /// Get the event this message is replying to, if any. pub fn in_reply_to(&self) -> Option { - as_variant!(self, TimelineItemContent::Aggregated).and_then(|agg| agg.in_reply_to.clone()) + as_variant!(self, Self::Aggregated)?.in_reply_to.clone() } /// Return the reactions, grouped by key and then by sender, for a given