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);
There is something I don't understand. How come the variable five doesn't call the plus_one function. How come it directly calls Some(5)?
That's because the "keywords" (None and Some) as you're calling them are actually tuple variants for Option which are imported by default. So really saying Some(x) Is Option::Some(x).
What I am trying to say is that in let five = Some(5); doesn't this call the plus_one function, cause it goes through the match case which is inside the plus_one function?