https://www.snoyman.com/blog/2018/10/rust-crash-course-02-basics-of-ownership

I also blog frequently on the Yesod Web Framework blog, as well as the FP Complete blog.

See a typo? Have a suggestion? Edit this page on Github

Arguably the biggest distinguishing aspect of Rust versus other popular programming languages is its ownership model. In this lesson, we’re going to hit the basics of ownership in Rust. You can read much more in the Rust book chapter on ownership.

This post is part of a series based on teaching Rust at FP Complete. If you’re reading this post outside of the blog, you can find links to all posts in the series at the top of the introduction post. You can also subscribe to the RSS feed.

Format

I’m going to be experimenting a bit with lesson format. I want to cover both:

As time goes on in this series, I intend to spend more time on the latter and less on the former, though we still need significant time on the former right now. I’m going to try approaching this by having the beginning of this post discuss ownership, and then we’ll implement a first version of bouncy afterwards.

This format may feel a bit stilted, feedback appreciated if this approach works for people.

Comparison with Haskell

I’m going to start by comparing Rust with Haskell, since both languages have a strong concept of immutability. However, Haskell is a garbage collected language. Let’s see how these two languages compare. In Haskell:

In Rust, data ownership is far more important: it’s a primary aspect of the language, and allows the language to bypass garbage collection. It also allows data to often live on the stack instead of the heap, leading to better performance. Also, it runs deterministically, making it a good approach for handling other resources like file handles.