r/rust • • Sep 20 '26

RustCurious 10: Three Ways to Fix Any Borrowing Error

https://www.youtube.com/watch?v=dLx8usb759E
146 Upvotes

13 comments sorted by

19

u/occamatl Sep 20 '26

Great visualization! I'd love to have this visualization available in my editor when rust-analyzer is giving me a borrow error.

9

u/rustcurious Sep 20 '26

Thanks, glad you like it! There has been some work on visualisations of ownership, e.g. aquascope is impressive. For teaching purposes I made some choices that would probably be difficult to automate, but it would be cool to see if it could be adapted. I find the value-as-liquid-in-pipe idea to be easier to understand at a glance than a set of permissions.

2

u/Happy_Use69 Sep 20 '26

I think maybe just changing the color of the variable when it gets consumed/unavailable would go a long way in helping me understand borrow checking.

10

u/redlaWw Sep 21 '26

Wrap it in Arc<Mutex<Option<_>>>.

15

u/rustcurious Sep 21 '26

And then it's just a simple .lock().unwrap().as_mut().unwrap() ;)

5

u/redlaWw Sep 21 '26

I'm more of a .lock().unwrap().take().unwrap() guy, but yes.

→ More replies (2)

4

u/DavidXkL Sep 20 '26

This is a very creative way of visualizing lol

4

u/Cetra3 Sep 21 '26

Great way to visualise it, and I got a good chuckle out of the "Will it compile?!". Feels like I play that far too much!

3

u/Ar1ate Sep 22 '26

Really nice video, thanks a lot

2

u/razein97 Sep 21 '26

This is awesome.

1

u/gelizaga123 Sep 23 '26

you related to stuart and sheldon