Part of the Rust Crash Course: https://www.youtube.com/playlist?list=PL6yRaaP0WPkWRsXJgdnw9lj1vchAaKwfS

Welcome to the Rust Crash Course

In this course, we will be learning Rust from scratch. This course is very fast paced and designed for programmers who already have some experience with another programming language such as Dart or JavaScript or Swift. We will talk about variables, constants, ownership, functions, structures, enumerations, collections such as tuples, vectors, hash-maps and iterators, optionals, error handling, lifetime specifiers, traits, pointers, generics, packages, crates, modules and paths, asynchronous programming and we will also create 2 sample applications using Rust to put all these concepts to use!

In this chapter we are going to go through a difficult concept for a lot of people to understand in Rust and that is ownership. We will look at the important ownership rules in Rust and how we can navigate our way around ownership rules in order to be able to build Rust applications.

Timestamps:
00:00 - Ownership
00:09 - Ownership is what confuses a lot of developers in Rust
00:45 - Let's look at an example
01:35 - Define your variables
01:56 - Print both variables
04:01 - Let's see why this happens in Rust
04:42 - Rust drops variables that go out of scope
07:59 - Stack vs heap
11:38 - A "String" is both in stack and heap
13:01 - Here is a good illustration
14:41 - Second name variable "name2" takes ownership
16:32 - Both "name1" and "name2" cannot free the data
18:20 - This is a concept called "moving"
19:29 - Moves happen using a "trait" called "Copy"
20:49 - Stack values copy (move) by default
22:59 - References
23:51 - References are written with an ampersand
24:28 - References point to valid data
28:16 - References don't drop a variable
29:19 - Let's have a look at a reference
32:31 - References can be mutable and immutable
33:02 - Create a function
33:54 - You cannot mutate the &String reference
35:21 - Now change the function to mutating
36:58 - Create a mutable variable in main()
37:08 - Pass it to your function
39:41 - You can have at most 1 mutable reference at a time
41:12 - This is to prevent data races
42:17 - No mutable references while immutable references are there
44:35 - That includes the original "mut name" variable
44:55 - Scope of variables is very important
46:27 - Dangling references
49:23 - Ownership is best learnt by practice


If you want to support my work, please consider joining my YouTube channel by pressing the Join button!

Twitter: https://twitter.com/vandadnp
LinkedIn: https://linkedin.com/in/vandadnp

Let's get started!