You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// _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.
The text was updated successfully, but these errors were encountered:
I would like to open a discussion about this page: Ownership and moves
The (paraphrased) code on the page says:
The comment says
// _Stack_ allocated integer
. I thought that u32 is copied because it implementsTrait 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 andlet 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.The text was updated successfully, but these errors were encountered: