rust-unofficial / patterns

A catalogue of Rust design patterns, anti-patterns and idioms
https://rust-unofficial.github.io/patterns/
Mozilla Public License 2.0
7.84k stars 354 forks source link

Borrow Checker Patterns #335

Open simonsan opened 1 year ago

simonsan commented 1 year ago

Inspired by the talk Rust in 2024 by Niko Matsakis (at 37m20s) I was thinking we may be able to create some more learning resources about that here to help to reduce accidental complexity for people being new to Rust.

We have an article about interacting with the borrow checker (Anti-Pattern/Clone to satisfy the borrow checker), but I feel that more a don't than how to interact usually with the borrow checker.

We may also revisit https://github.com/rust-unofficial/patterns/pull/323 to make these things overall more visible, I even thought about a new category for "Borrow Checker Pattterns" because they are quite exclusive to Rust (and may change within each edition).

simonsan commented 1 year ago

Would be nice if we could collect some ideas of which topics/quirks to cover or, in general, what would be a reasonable approach to the overall topic of borrow checker patterns.

Owen-CH-Leung commented 1 year ago

I feel like to fully understand borrow & checker, we should cover the following topics :

https://github.com/rust-lang/rustlings/tree/main/exercises/move_semantics

@simonsan What's your thoughts on this ?