-
Notifications
You must be signed in to change notification settings - Fork 381
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
Adding 'clone to satisfy the borrow checker' anti-pattern #23
Conversation
|
||
## Example | ||
|
||
```rust fn main() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "rust" and "fn main()" should be on separate lines, like this:
```rust
fn main() {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I don't think you need to wrap the code in fn main()
-- the other examples in this repo (along with the official docs) keep the code bare.
// x has been borrowed | ||
// thanks to x.clone(), x was never borrowed, and this line will run. | ||
println!("{}", x); | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can come up with a better example; I'm not sure if this is really a problem when your type is copy. Let me play around with some examples and get back to you.
I like your motivation and description. I think we can make improve this section quite a bit if we put a little more polish into the example, and add examples that shows how you can avoid the problems. I'll play around with a few ideas and get back to you. |
So I tried to think of some good examples, what do you think about this one
I could imagine someone trying to add a |
I have a few ideas for examples:
Hope that helps. |
Anything left for this? |
@liamzdenek any updates on this? |
Closing due to inactivity. Further additions to the PR can be made in #110. |
I feel like this write-up could be improved, but I'm not exactly sure how -- recommendations and modifications are welcome.