Skip to content

refactor(sdk-ui): remove expect() with better borrow#6513

Merged
Hywan merged 2 commits intomainfrom
valere/follow_up_aggregation_cleaning
May 1, 2026
Merged

refactor(sdk-ui): remove expect() with better borrow#6513
Hywan merged 2 commits intomainfrom
valere/follow_up_aggregation_cleaning

Conversation

@BillCarsonFr
Copy link
Copy Markdown
Member

Follow up on review on this PR #6494 (comment)

Remove the usage of if/expect that was introduced because of a borrowing problem.
Instead we use ok_or_else, but we clone the debug_string early (to avoid needing to borrow event again in the ok_or_else), it is not ideal either but better that the expect/panic

I also removed the is_rtc_notification and is_live_location that was created I believe just to avoid the borrowing problem? They were only used in test and it just a shortcut for matches!()

  • I've documented the public API Changes in the appropriate CHANGELOG.md files.
  • This PR was made with the help of AI.

Signed-off-by:

@BillCarsonFr BillCarsonFr requested a review from a team as a code owner April 28, 2026 08:14
@BillCarsonFr BillCarsonFr requested review from poljar and removed request for a team April 28, 2026 08:14
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 28, 2026

Codecov Report

❌ Patch coverage is 64.28571% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.87%. Comparing base (3ac1f06) to head (7273568).
⚠️ Report is 26 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...rix-sdk-ui/src/timeline/controller/aggregations.rs 64.28% 5 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6513   +/-   ##
=======================================
  Coverage   89.87%   89.87%           
=======================================
  Files         381      381           
  Lines      105781   105758   -23     
  Branches   105781   105758   -23     
=======================================
- Hits        95071    95051   -20     
- Misses       7048     7051    +3     
+ Partials     3662     3656    -6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Copy Markdown
Member

@Hywan Hywan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my proposal to avoid allocating the debug_string for nothing if event is a poll.

fn poll_state_from_item<'a>(
event: &'a mut Cow<'_, EventTimelineItem>,
) -> Result<&'a mut PollState, AggregationError> {
if event.content().is_poll() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if the following works but it seems ok:

if let TimelineItemContent::MsgLike(MsgLikeContent { kind: MsgLikeKind::Poll(state), ..}) = event.to_mut().content_mut() {
    Ok(state)
} else {
    Err(AggregationError::InvalidType {
        expected: "a poll".to_owned(),
        actual: event.content().debug_string().to_owned(),
    })
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will have the borrow issue :/ event.to_mut() borrows event mutably for the lifetime 'a so for all the function scope, thus you cannot borrow again in the else

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

@Hywan Hywan Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested the following and it works:

let content = event.to_mut().content_mut();

if let TimelineItemContent::MsgLike(MsgLikeContent { kind: MsgLikeKind::Poll(state), .. }) =
    content
{
    Ok(state)
} else {
    Err(AggregationError::InvalidType {
        expected: "a poll".to_owned(),
        actual: content.debug_string().to_owned(),
    })
}

@Hywan Hywan removed the request for review from poljar April 28, 2026 08:37
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 28, 2026

Merging this PR will not alter performance

✅ 50 untouched benchmarks


Comparing valere/follow_up_aggregation_cleaning (7273568) with main (e90dbb3)

Open in CodSpeed

@BillCarsonFr BillCarsonFr changed the title refactor(sdk-ui): use ok_or_else instead of if/expect refactor(sdk-ui): remove expect() with better borrow Apr 29, 2026
Copy link
Copy Markdown
Member

@Hywan Hywan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks great, thanks!

@Hywan Hywan merged commit 4e8ceaa into main May 1, 2026
54 checks passed
@Hywan Hywan deleted the valere/follow_up_aggregation_cleaning branch May 1, 2026 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants