DEV Community

Cover image for Rust Series01 - Ownership is what you need to know
Kevin Sheeran
Kevin Sheeran

Posted on

Rust Series01 - Ownership is what you need to know

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");
Enter fullscreen mode Exit fullscreen mode

•s owns the heap memory for "hello"
•When s goes out of scope → memory is freed automatically

Top comments (0)