So I've recently started learning the Rust language, I've been reading and writing the given figures as I go I'm currently at Chapter 6.2 of the documentation book (The match Control Flow Construct - The Rust Programming Language). For some reason, Listing 6-5 just will not compile on my setup
fn plus_one(x: Option<i32>) -> Option<i32> {
match x {
None => None,
Some(i) => Some(i + 1),
}
}
let five = Some(5);
let six = plus_one(five);
let none = plus_one(None);
No matter what, it spits out 2 errors of the same type - one for None => None, and one for Some(i) => Some(i + 1), as follows:
error[E0308]: mismatched types
--> src/main.rs:94:17
|
92 | fn plus_one(x: Option<i32>) -> Option<i32> {
| ----------- expected `Option<i32>` because of return type
93 | match x {
94 | None => None,
| ^^^^ expected enum `Option`, found enum `std::option::Option`
I feel like I'm losing my mind here, am I missing something? What is going wrong with this?