I finished reading "Book" and now I read "Rust by Example".
Here I found example of code
This example output is
Point occupies 16 bytes on the stack
Rectangle occupies 32 bytes on the stack
Boxed point occupies 8 bytes on the heap
Boxed rectangle occupies 8 bytes on the heap
Boxed box occupies 8 bytes on the heap
Unboxed point occupies 16 bytes on the stack
All boxed data only show size of pointer, not size of data, but in my knowledge pointers live on stack and not on heap. They only point to data on heap. So, in my option this example is not right. It should say:
Boxed point occupies 8 bytes on the stack and 16 bytes on the heap.
Now it looks like point on the heap takes less memory than point on stack. Even boxed rectangle occupies only 8 bytes on heap. So if we moved all this forum data on heap it would take only 8 bytes in RAM
That example definitely looks wrong. One potential fix would be something like this:
println!("Boxed point occupies {} bytes on the stack",
mem::size_of_val(&boxed_point));
println!("Boxed point occupies {} bytes on the heap",
mem::size_of_val(&*boxed_point));
which gives
Boxed point occupies 8 bytes on the stack
Boxed point occupies 16 bytes on the heap