1 00:00:05,660 --> 00:00:06,350 In this video. 2 00:00:06,350 --> 00:00:11,420 I'm going to take a second to explain why I structured the course the way that I did. 3 00:00:11,960 --> 00:00:14,570 Starting off with the basics. 4 00:00:14,960 --> 00:00:17,390 These are the programming building blocks. 5 00:00:17,630 --> 00:00:25,250 And these principles hold true to every programming language where we have variables, functions, control, 6 00:00:25,250 --> 00:00:31,990 flow, etc. because variables are going to be how we store and represent data and then functions are 7 00:00:32,060 --> 00:00:38,630 going to be how we can organize logic in our code and then control flow is going to be how we can account 8 00:00:38,630 --> 00:00:46,160 for situations and execute code based on those situations and potentially other parameters that we check 9 00:00:46,160 --> 00:00:46,670 for. 10 00:00:48,260 --> 00:00:54,110 Following that, we're going to talk about some of the principles that drive rust. 11 00:00:54,110 --> 00:00:56,780 Rust is known for having memory safety. 12 00:00:57,540 --> 00:01:06,450 And to ensure memory safety, there has to be some components that the language is able to validate 13 00:01:06,780 --> 00:01:11,280 in order for us to be assured that we have memory safety. 14 00:01:11,580 --> 00:01:16,920 And these are going to pertain to ownership, borrowing and references. 15 00:01:18,300 --> 00:01:24,510 And then once we're able to kind of understand some of the Russ principles, then we can start getting 16 00:01:24,510 --> 00:01:32,400 into a little bit more complex code examples, such as looking at structs and lifetimes. 17 00:01:32,640 --> 00:01:39,900 Structs are pretty easy to work with, and it's just going to allow us to organize data related to a 18 00:01:39,900 --> 00:01:40,980 common type. 19 00:01:41,160 --> 00:01:47,010 And then lifetimes are really important in rest because it's going to allow the borrow checker to keep 20 00:01:47,010 --> 00:01:50,010 track of how long references are valid for. 21 00:01:50,100 --> 00:01:57,960 And this is going to allow the compiler to make sure that we don't have memory issues such as dangling 22 00:01:57,960 --> 00:01:58,920 references. 23 00:02:02,110 --> 00:02:12,370 E nums and pattern matching e nums are or enumerations are a data type consisting of a set of named 24 00:02:12,370 --> 00:02:22,300 values to help us with abstraction and pattern matching is going to allow us to look and identify if 25 00:02:22,300 --> 00:02:32,560 a value matches a pattern that we have specified and if we have a match, then we execute code based 26 00:02:32,560 --> 00:02:35,800 on what that match was. 27 00:02:35,800 --> 00:02:46,030 But if there's not a match, well then we also know that we have code that we can execute in that situation 28 00:02:46,030 --> 00:02:46,660 as well. 29 00:02:48,810 --> 00:02:51,720 And then we'll follow that up with traits in generics. 30 00:02:51,720 --> 00:02:57,810 So traits are a group of methods that are defined for a particular type, and it's going to be an abstract 31 00:02:57,810 --> 00:03:01,980 definition of shared behavior amongst different types. 32 00:03:02,160 --> 00:03:07,440 And then generics are going to allow our code to be polymorphic meaning. 33 00:03:07,440 --> 00:03:11,130 We do not have to specify the type until compile time. 34 00:03:12,030 --> 00:03:16,050 So for example, we have integers and strings. 35 00:03:16,050 --> 00:03:20,250 Well, we can create code that will be able to. 36 00:03:22,240 --> 00:03:28,090 Operate efficiently on whether our type is an integer or if our type is a string. 37 00:03:29,230 --> 00:03:32,380 And then following that up, we'll look at some common collections. 38 00:03:32,860 --> 00:03:36,880 And these are just data structures that are given to us in the standard library. 39 00:03:36,880 --> 00:03:43,210 And we'll look at what vectors are and we'll look at binary heap, and then we'll also look at maps 40 00:03:43,210 --> 00:03:50,620 and sets and we'll dive into all the associated methods that come with all of these data structures. 41 00:03:52,390 --> 00:03:54,490 And then we'll look at air handling. 42 00:03:54,490 --> 00:04:00,160 And this is going to allow us to write robust code because code can have failures. 43 00:04:00,160 --> 00:04:10,330 So it is important for the programmer to be able to handle failures that may or may not happen, because 44 00:04:10,330 --> 00:04:16,180 if we don't handle them and then we have a failure, well, our program won't know what to do. 45 00:04:16,180 --> 00:04:20,080 And if our program does not know what to do, then we panic. 46 00:04:20,080 --> 00:04:27,400 So, for example, if we have a web server that does not have air handling and we have an error occur, 47 00:04:27,430 --> 00:04:29,530 well then our web server is going to crash. 48 00:04:29,530 --> 00:04:36,340 Therefore, we no longer have a web server that is up and running handling request, which is obviously 49 00:04:36,730 --> 00:04:37,660 really bad. 50 00:04:39,220 --> 00:04:41,980 And then also important is testing. 51 00:04:41,980 --> 00:04:48,940 And testing is important because it will allow us to ensure that our program is operating as we expect 52 00:04:49,120 --> 00:04:52,060 and it might help us find some bugs. 53 00:04:52,840 --> 00:04:59,320 It's also important because as you add code changes, you want to make sure that new code does not break 54 00:05:00,520 --> 00:05:02,350 already existing code. 55 00:05:02,350 --> 00:05:11,290 So it's also a way to verify that as you expand your program or refactor it, that your program continues 56 00:05:11,290 --> 00:05:13,690 to work the way it has in the past. 57 00:05:15,770 --> 00:05:23,300 And then we get into some of the functional programming aspects of Rust, which are integrators and 58 00:05:23,300 --> 00:05:30,980 closures and integrators are essentially how we can count over a range of something. 59 00:05:30,980 --> 00:05:39,170 So from 0 to 10 we can iterate over one, two, three, four, five, six, seven, eight, nine. 60 00:05:40,220 --> 00:05:48,110 And then closures are anonymous functions that we can save in a variable or even pass as arguments to 61 00:05:48,110 --> 00:05:49,190 other functions. 62 00:05:49,190 --> 00:05:54,590 And this is just a simple way to allow us to be expressive in our code. 63 00:05:56,590 --> 00:06:06,580 And then we go to pointers and Rust has smart pointers such as Box, RC and Arc. 64 00:06:07,000 --> 00:06:09,640 And then we also have ref cell. 65 00:06:09,760 --> 00:06:17,080 Now all of these are heap allocated, which is a type of memory and we will be able to we'll talk about 66 00:06:17,080 --> 00:06:23,920 that more as we dive into what pointers are and pointers allow us to directly play with memory. 67 00:06:25,030 --> 00:06:36,220 Pointers are very important because it allows us to store types that don't have a predefined size and 68 00:06:36,670 --> 00:06:41,770 that's why we are able to put them on the heap instead of the stack. 69 00:06:43,210 --> 00:06:50,800 And then we have concurrency and concurrency is going to let our program do more thing at once, essentially. 70 00:06:50,800 --> 00:06:51,340 Right. 71 00:06:51,340 --> 00:06:55,780 But there is concurrency and then there's also parallelism. 72 00:06:55,960 --> 00:06:59,800 And these are kind of different things. 73 00:07:00,700 --> 00:07:03,040 There's a lot of different definitions out there. 74 00:07:03,340 --> 00:07:12,760 But simply concurrency is a task of running or managing multiple computations at the same time, whereas 75 00:07:12,760 --> 00:07:19,060 parallelism is a task of running multiple computations simultaneously. 76 00:07:19,600 --> 00:07:28,300 So an example of parallelism, you throw laundry in the washing machine, but you also have clothes 77 00:07:28,300 --> 00:07:30,190 in the dryer at the same time, right? 78 00:07:30,190 --> 00:07:34,000 So you're washing clothes and also drying clothes at the same time. 79 00:07:34,330 --> 00:07:44,290 And then for concurrency, let's say you have an array and you want to sort the array. 80 00:07:45,010 --> 00:07:51,670 So you give it, you create a sort algorithm, create two threads, and then divvy the work out equally 81 00:07:51,670 --> 00:07:53,550 amongst the two threads. 82 00:07:53,560 --> 00:07:54,160 Right? 83 00:07:54,160 --> 00:08:01,750 So we'll be able to get a better understanding of that when we talk about concurrency and use a library 84 00:08:01,750 --> 00:08:10,510 known as Rayon, and then we're going to talk about macros and unsafe code macros are just a way of 85 00:08:10,510 --> 00:08:11,680 meta programming. 86 00:08:11,950 --> 00:08:22,900 So essentially what that means is we're going to use code to write code and then unsafe code is a feature 87 00:08:22,900 --> 00:08:27,460 in Rust because sometimes you might have to write unsafe code. 88 00:08:27,460 --> 00:08:33,130 And what this means is that the compiler is not going to check it for memory safety. 89 00:08:33,370 --> 00:08:40,870 So you're basically telling the compiler, Hey, I know that my code is safe, so I don't need you to 90 00:08:40,870 --> 00:08:42,270 check it per say. 91 00:08:42,280 --> 00:08:50,200 So it's really important that when you use unsafe code that you double check it to make sure that you 92 00:08:50,200 --> 00:08:53,500 are complying to memory safety. 93 00:08:55,270 --> 00:09:00,580 And then lastly, we're going to talk about asynchronous rust. 94 00:09:00,580 --> 00:09:08,140 And this is a technique in programming to allow the execution to continue in a program, even if there 95 00:09:08,140 --> 00:09:09,970 is a long running task. 96 00:09:10,210 --> 00:09:15,100 And execution will halt once the value from that long running task is needed. 97 00:09:15,100 --> 00:09:24,310 And what I mean by this is, say we kick off a function that's going to take one minute to run. 98 00:09:24,610 --> 00:09:30,940 Well, we don't want our program to wait one minute if we don't need that function until later on in 99 00:09:30,940 --> 00:09:32,230 our execution. 100 00:09:32,410 --> 00:09:39,250 So we'll kick that function off and keep executing our program until the value from that one minute 101 00:09:39,250 --> 00:09:40,930 long function is needed. 102 00:09:40,930 --> 00:09:44,980 And when that value is needed, then our program will stop and wait. 103 00:09:44,980 --> 00:09:52,150 And what this does is it's going to decrease our CPU wait time and it allows us to use our resources 104 00:09:52,150 --> 00:09:55,330 more efficiently, giving us a better runtime. 105 00:09:57,210 --> 00:10:01,770 And if at any point during any of the lectures you have a question. 106 00:10:01,890 --> 00:10:10,200 Udemy provides a Q&A section, so please use it and ask any questions at any point regarding anything 107 00:10:10,200 --> 00:10:11,280 rust related. 108 00:10:11,790 --> 00:10:18,810 I hope you enjoy this journey and I look forward to helping you gain a better understanding of rust.