Open simonsan opened 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.
I feel like to fully understand borrow & checker, we should cover the following topics :
Explanation of Borrowing Rules: While Rust's borrowing rules are documented, it would be helpful to have more in-depth explanations and examples that show these rules in action.
Common Borrow Checker Errors: A guide to common borrow checker errors, their causes, and how to resolve them could be very helpful for new Rust developers.
Borrowing in Different Contexts: Borrowing behaves differently in different contexts (e.g., in struct fields, in loops, in closures). Each of these could be a topic of its own.
Patterns for Avoiding Borrow Checker Errors: Some coding patterns can help avoid borrow checker errors. For example, splitting functions, using Rc and RefCell for shared ownership, or using the Cow type for efficient cloning.
Understanding Lifetimes: Lifetimes are a crucial part of the borrow checker, but they can be confusing for newcomers. More resources on understanding and using lifetimes could be very valuable.
Move semantics: Lastly, we should also provide some materials with regard to the concept of move. Speak of this, I found rustlings exercise on move semantics very useful.
https://github.com/rust-lang/rustlings/tree/main/exercises/move_semantics
@simonsan What's your thoughts on this ?
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).