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

Ownership and moves page lacks explanation #1820

Open
BAEGregS opened this issue Feb 19, 2024 · 0 comments
Open

Ownership and moves page lacks explanation #1820

BAEGregS opened this issue Feb 19, 2024 · 0 comments

Comments

@BAEGregS
Copy link

I would like to open a discussion about this page: Ownership and moves

The (paraphrased) code on the page says:

// _Stack_ allocated integer
let x = 5u32;
// *Copy* `x` into `y` - no resources are moved
let y = x;

// `a` is a pointer to a _heap_ allocated integer
let a = Box::new(5i32);
// *Move* `a` into `b`
let b = a;

The comment says // _Stack_ allocated integer. I thought that u32 is copied because it implements Trait std::marker::Copy, not because it happens to be on the stack. Am I unclear on the concept?

Copy vs. move is a super-important concept, and I think that there should be an explicit explanation here of WHY let y = x; is a copy and let b = a; is a move. That might mean one short paragraph mentioning Copy and why u32 implements by default it would be good. Also, a link to the trait Copy page. Even if this information is elsewhere in the book, I still think it still should be made explicitly clear here.

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

No branches or pull requests

2 participants