refactor(timeline): bump as_variant and make more use of its pattern matching form

This commit is contained in:
Benjamin Bouvier
2025-03-27 10:09:20 +01:00
parent 4f3b40d6fb
commit f6e223edf6
3 changed files with 9 additions and 13 deletions
Generated
+2 -2
View File
@@ -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"
+1 -1
View File
@@ -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"
@@ -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<OwnedEventId> {
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<InReplyToDetails> {
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