Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use Option<&mut T> instead of &mut Option<T>in a few places #4702

Merged
merged 2 commits into from
Feb 20, 2025

Conversation

bnjbvr
Copy link
Member

@bnjbvr bnjbvr commented Feb 20, 2025

This is generally a good practice, as it makes some APIs less awkward to call (in particular, callers don't have to pass &mut None when they're not interested in the optional value).

There are a few other instances of this in the code base, but after spending a few minutes trying to move them to Option<&mut>, turns out I couldn't:

  • in matrix-sdk/src/sync.rs, the option is overridden at the end of the function with a new value.
  • in matrix-sdk-crypto/src/identities/manager, we're actually overriding the passed &mut Option with a new Option value.
  • in matrix-sdk-common/src/linked_chunk/mod.rs, the two remaining functions using &mut Option pass it multiple times, and strangely i can't clone a Option<&mut T>; I suspect the mutability makes it impossible, because it would be another live mutable alias to the inner value.

@bnjbvr bnjbvr requested a review from a team as a code owner February 20, 2025 15:13
@bnjbvr bnjbvr requested review from jmartinesp and removed request for a team February 20, 2025 15:13
@bnjbvr bnjbvr changed the title refactor: use Option<&mut T> instead of &mut Option<T>in Client:delay_sync refactor: use Option<&mut T> instead of &mut Option<T>in a few places Feb 20, 2025
@bnjbvr bnjbvr enabled auto-merge (rebase) February 20, 2025 15:22
@bnjbvr bnjbvr merged commit 60efcbc into main Feb 20, 2025
42 checks passed
Copy link

codecov bot commented Feb 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.89%. Comparing base (61fa339) to head (1de5e76).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4702      +/-   ##
==========================================
- Coverage   85.90%   85.89%   -0.02%     
==========================================
  Files         292      292              
  Lines       33907    33907              
==========================================
- Hits        29127    29123       -4     
- Misses       4780     4784       +4     

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

@bnjbvr bnjbvr deleted the bnjbvr/change-a-few-refmutoption-to-optionrefmut branch February 20, 2025 15:28
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