Back to articles
[Rust Guide] 4.2. Ownership Rules, Memory, and Allocation

[Rust Guide] 4.2. Ownership Rules, Memory, and Allocation

via Dev.toSomeB1oody

4.2.0 Before We Begin After learning Rust’s general programming concepts, you’ve arrived at the most important topic in all of Rust— ownership . It’s quite different from other languages, and many beginners find it hard to learn. This chapter aims to help beginners fully master this feature. This chapter has three sections: Ownership: Stack Memory vs. Heap Memory Ownership Rules, Memory, and Allocation (this article) Ownership and Functions If you find this helpful, please like, bookmark, and follow. To keep learning along, follow this series. 4.2.1 Ownership Rules Ownership has three rules: Every value has a variable, and that variable is the owner of the value Every value can only have one owner at a time When the owner goes out of scope, the value is deleted 4.2.2 Variable Scope Scope is the valid range of an item in a program. fn main (){ // machine is not available let machine = 6657 ; // machine is available // operations can be performed on machine } // machine’s scope ends here

Continue reading on Dev.to

Opens in a new tab

Read Full Article
0 views

Related Articles