The option enum is important because it allows us to either allow a value to be something or it could
be nothing.
The nothing aspect is comparable to Nohl and other languages, whereas Rust does not have the Noel feature,
it just uses none inside the option in them.
So let's look to see how the option enum is set up.
So we have enum option of a generic DT, which we will learn about in the next section.
And then inside this enum we have none and then we have some T and that's all there is to it.
To the option enum.
The.
T means it is generic, which as I said, we will cover in the next section.
But to simply put it, it can hold a piece of data of any type.
You do not have to do anything in order to use this option in them as it is already available inside
the scope for us already.
So I can delete all of this.
And then here we can say let some number.
Equals some five.
And just to make it clean, clean it up, let some string.
And this is going to be a reference to a string slice, but a string.
And then we can say let nothing equal of an option and we'll specify that it's also an eight.
Equals none.
So all of these are valid and it is important to know that option.
T So what we have here, this is the same thing as saying we're declaring the type.
But behind the scenes, before we say it's an idea, it is option T whereas.
Let X equals five is equal to an I 32.
So I guess just to really clarify this, let's make that an I 32.
These two when we declare option I 32 and then we declare a variable to have five, which is I 32 by
default.
These are not the same.
So we can show this by saying let x of I 32 equal to five, and then it will say Let Y.
Of Option I 32 also equal to five.
That helps if I put the some keyword.
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
add option of EI 32 to EI 32.
So you would have to convert the option of I 32 to an I 32 before we could perform this operation.
So to wrap up what an option enum is and when we want to use it, we would want some code that would
run, but only when we have some key.
And then that code uses the inner T and remember, PT is the data type.
We would also want code to handle the case of when we have none.
So we want code that can be able to handle something or nothing.
Well, luckily for us, we had Rust gives us the match expression, which is a control flow construct
that does exactly this when we use it with enemies.
So let's take a look at how that match statement works in the next lecture.