This is aimed for people who are coming to Rust from garbage collected languages, such as Python or JavaScript and have trouble with the compiler thro

Rust – What made it “click” for me (Ownership & memory internals)

submited by
Style Pass
2021-06-11 16:30:06

This is aimed for people who are coming to Rust from garbage collected languages, such as Python or JavaScript and have trouble with the compiler throwing errors without reason. This guide assumes you already know some Rust.

For those like me that worked with non-GC languages (C, C++) the borrow checker still feels hard to understand at first, but the learning curve is quite less and the documentation and design makes quite a lot of sense.

So I want to add some basic context for those that never managed manually requesting and freeing memory such that the underlying design in Rust ownership system makes more sense and clicks. Because this is all it takes, once it clicks, everything seems to fall together. (If you already know C or C++, you’ll already know most of the stuff I’m going to talk about, and probably notice that I’m oversimplifying a lot; but it might be worth the read as it contains how Rust “clicked” for me)

Usually in GC languages assignment can do two things depending on the types involved. For basic types (i.e. numeric) the value inside ‘a’ is usually copied into ‘b’, so you end with two variables with the same content. For complex types it is common to instead of copying the data just make “b” point to “a”, so internally they share the same data.

Leave a Comment