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

New question about cloning references #22

Merged
merged 1 commit into from
Jul 6, 2019
Merged

Conversation

peterjoel
Copy link
Contributor

My original idea was a bit more complicated: https://gist.github.com/peterjoel/8975ab7ff3211d72d3704c948d21a0b0

The more tricky part of that (B is actually a fn, which is Clone and has zero size) can be a separate question.

Copy link
Owner

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This is a terrific question.

@dtolnay dtolnay merged commit 0d23407 into dtolnay:master Jul 6, 2019
@dtolnay
Copy link
Owner

dtolnay commented Jul 6, 2019

Published to https://dtolnay.github.io/rust-quiz/30.
(You may need to refresh https://dtolnay.github.io/rust-quiz/questions.js before you can see it.)

I made some changes to the explanation in 86b825f. Basically I found it clearer to focus on what type parameter the generic function is instantiated with, and present the answer in terms of X = &A, X = () etc.

To facilitate that, I renamed the type parameter from T to X so that it doesn't get mixed it up when talking about references &T and Rc<T> in general where the symbol T does not refer specifically to the type parameter of our specific function in the quiz code.

I filled in some relevant detail as well:

  • Why does b.clone() not call the impl for &()?

  • Why does impl Clone for &T exist if it is so confusing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants