Personal Understanding of Rust Ownership
Stack and Heap The first thing to understand about ownership is to know about the stack and heap memory. This concept will be quite easy if you have learned C or C++, since they are almost the same. Stack Memory If you simply declare a variable in a function, then it will live in the stack. For example, the code below declares some such variables: fn main() { let a = 1; let y = plus_one(a); } fn plus_one(x: i32) -> i32 { x + 1 } The variables a, x, and y are all allocated and deallocated automatically, just like C/C++ compiler. ...