Hi fellows, since I've been using Rust for about 3 years now, I think it's time to share some experience to you guys, so I decide to post this Rust language learning series in next couple of weeks. Without further do, let's jump into it.
Assume you know some OOP(Oriented-Object-Programming) languages, like Java, C#. you will understand that everything is based on Object, but today you need to shift your mind as Rust is not an OOP language, instead it is all about ownership which means Rust will ask you explicitly who owns memory.
So Ownership answers one question:
Who is responsible for freeing this memory?
The core ownership rule (only one owner)
Every value in Rust has exactly ONE owner at any time
let s = String::from("hello");
•s owns the heap memory for "hello"
•When s goes out of scope → memory is freed automatically
Top comments (0)