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

Borrow Checker Patterns #335

Open
simonsan opened this issue Dec 24, 2022 · 2 comments
Open

Borrow Checker Patterns #335

simonsan opened this issue Dec 24, 2022 · 2 comments
Labels
A-pattern Area: Content about Patterns C-addition Category: Adding new content, something that didn't exist in the repository before E-help wanted Call for participation: Help is requested to fix this issue

Comments

@simonsan
Copy link
Collaborator

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 #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 simonsan added the A-pattern Area: Content about Patterns label Dec 24, 2022
@simonsan
Copy link
Collaborator Author

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.

@simonsan simonsan added E-help wanted Call for participation: Help is requested to fix this issue C-addition Category: Adding new content, something that didn't exist in the repository before labels Apr 8, 2023
@Owen-CH-Leung
Copy link
Contributor

Owen-CH-Leung commented May 25, 2023

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-pattern Area: Content about Patterns C-addition Category: Adding new content, something that didn't exist in the repository before E-help wanted Call for participation: Help is requested to fix this issue
Projects
None yet
Development

No branches or pull requests

2 participants