1 00:00:05,940 --> 00:00:12,480 The option enum is important because it allows us to either allow a value to be something or it could 2 00:00:12,480 --> 00:00:13,080 be nothing. 3 00:00:14,200 --> 00:00:21,580 The nothing aspect is comparable to Nohl and other languages, whereas Rust does not have the Noel feature, 4 00:00:21,640 --> 00:00:24,790 it just uses none inside the option in them. 5 00:00:24,790 --> 00:00:27,850 So let's look to see how the option enum is set up. 6 00:00:27,850 --> 00:00:35,770 So we have enum option of a generic DT, which we will learn about in the next section. 7 00:00:36,100 --> 00:00:45,910 And then inside this enum we have none and then we have some T and that's all there is to it. 8 00:00:45,910 --> 00:00:47,230 To the option enum. 9 00:00:47,560 --> 00:00:48,250 The. 10 00:00:49,160 --> 00:00:53,000 T means it is generic, which as I said, we will cover in the next section. 11 00:00:53,000 --> 00:00:57,500 But to simply put it, it can hold a piece of data of any type. 12 00:00:57,740 --> 00:01:03,890 You do not have to do anything in order to use this option in them as it is already available inside 13 00:01:03,890 --> 00:01:05,120 the scope for us already. 14 00:01:05,120 --> 00:01:07,070 So I can delete all of this. 15 00:01:08,750 --> 00:01:12,590 And then here we can say let some number. 16 00:01:14,390 --> 00:01:17,060 Equals some five. 17 00:01:19,000 --> 00:01:24,220 And just to make it clean, clean it up, let some string. 18 00:01:24,220 --> 00:01:30,220 And this is going to be a reference to a string slice, but a string. 19 00:01:31,630 --> 00:01:42,430 And then we can say let nothing equal of an option and we'll specify that it's also an eight. 20 00:01:44,250 --> 00:01:47,910 Equals none. 21 00:01:48,360 --> 00:01:53,430 So all of these are valid and it is important to know that option. 22 00:01:53,430 --> 00:01:59,460 T So what we have here, this is the same thing as saying we're declaring the type. 23 00:01:59,460 --> 00:02:07,020 But behind the scenes, before we say it's an idea, it is option T whereas. 24 00:02:09,410 --> 00:02:15,560 Let X equals five is equal to an I 32. 25 00:02:15,590 --> 00:02:19,280 So I guess just to really clarify this, let's make that an I 32. 26 00:02:21,870 --> 00:02:29,970 These two when we declare option I 32 and then we declare a variable to have five, which is I 32 by 27 00:02:29,970 --> 00:02:30,690 default. 28 00:02:30,720 --> 00:02:31,950 These are not the same. 29 00:02:32,730 --> 00:02:43,110 So we can show this by saying let x of I 32 equal to five, and then it will say Let Y. 30 00:02:44,660 --> 00:02:51,320 Of Option I 32 also equal to five. 31 00:02:53,420 --> 00:02:58,990 That helps if I put the some keyword. 32 00:03:01,040 --> 00:03:10,370 So now if we try to add these let some equals to x plus Y, we see we get an error and it says we cannot 33 00:03:10,370 --> 00:03:13,850 add option of EI 32 to EI 32. 34 00:03:14,530 --> 00:03:21,760 So you would have to convert the option of I 32 to an I 32 before we could perform this operation. 35 00:03:22,540 --> 00:03:29,170 So to wrap up what an option enum is and when we want to use it, we would want some code that would 36 00:03:29,170 --> 00:03:33,130 run, but only when we have some key. 37 00:03:33,730 --> 00:03:38,830 And then that code uses the inner T and remember, PT is the data type. 38 00:03:39,400 --> 00:03:43,150 We would also want code to handle the case of when we have none. 39 00:03:44,340 --> 00:03:49,230 So we want code that can be able to handle something or nothing. 40 00:03:49,350 --> 00:03:55,080 Well, luckily for us, we had Rust gives us the match expression, which is a control flow construct 41 00:03:55,080 --> 00:03:59,000 that does exactly this when we use it with enemies. 42 00:03:59,010 --> 00:04:03,690 So let's take a look at how that match statement works in the next lecture.