Rust Contagious Borrow Issue
Posted2 months agoActive2 months ago
qouteall.funTechstory
calmpositive
Debate
20/100
Rust ProgrammingBorrow CheckerSoftware Development
Key topics
Rust Programming
Borrow Checker
Software Development
The post discusses strategies for avoiding common issues with Rust's borrow checker, specifically the 'contagious borrow issue', and the discussion revolves around sharing experiences and tips for working with Rust.
Snapshot generated from the HN discussion
Discussion Activity
Light discussionFirst comment
4h
Peak period
4
12-18h
Avg / period
2.5
Key moments
- 01Story posted
Oct 24, 2025 at 8:10 AM EDT
2 months ago
Step 01 - 02First comment
Oct 24, 2025 at 11:58 AM EDT
4h after posting
Step 02 - 03Peak activity
4 comments in 12-18h
Hottest window of the conversation
Step 03 - 04Latest activity
Oct 27, 2025 at 10:46 AM EDT
2 months ago
Step 04
Generating AI Summary...
Analyzing up to 500 comments to identify key contributors and discussion patterns
ID: 45693814Type: storyLast synced: 11/20/2025, 1:48:02 PM
Want the full context?
Jump to the original sources
Read the primary article or dive into the live Hacker News thread when you're ready.
[1] https://rust-unofficial.github.io/too-many-lists/
In general, "stop, drop, reacquire" is a good motto. ie finish figuring out what you want to happen, release the resources that you needed to figure that out, reacquire exactly the resources you need to make the thing happen, do it. That's basically the premise of 'mutation-as-data'.
I wouldn't say this is a super common problem (though I have hit it). The opening example here is that logic outside `Parent` is maintaining its summary state based on its children. That's unusual; typically `Parent` itself would be responsible for that, and so you can inline the logic without having to expose the fields.
Sometimes inlining the logic gets impractical though if the logic is super long. In that case it can be helpful to split it into sub-structs so that you can easily call a method on a group of fields. I did that here, for example: <https://github.com/scottlamb/moonfire-nvr/blob/ff383147e4ff7...>
There have been language proposals to define "view types" which are basically groups of fields that are borrowed. <https://smallcultfollowing.com/babysteps/blog/2021/11/05/vie...> IMHO, they're not worth the extra language complexity.
(That simplified example is just for illustrating contagious borrow issue. The *`total_score` is analogous to a complex state that exists in real applications*. Same for subsequent examples. Just summing integer can use `.sum()` or local variable. Simple integer mutable state can be workarounded using `Cell`.)
(Although we're a bit there with functions returning an impl)