I was just wondering... Wouldn't Nullabe<T>
be a better name than Option<T>
? Something like this:
enum Nullable<T> {
Null,
Value(T),
}
Option really sounds awkward to me for this usecase
Edit (added later):
Given this function signature:
fn plus_one(x: Option<i32>) -> Option<i32> {
}
In my opinion, there is zero chance someone who has not read the rust documents can tell what this function does. But this function:
fn plus_one(x: Nullable<i32>) -> Nullable<i32> {
}
I'd say any programmer can tell this function is a function that is able to handle null values. In my opinion Rust really has weird syntax sometimes. For example:
let config_max = Some(3u8);
if let Some(max) = config_max {
println!("The maximum is configured to be {}", max);
}
Couldn't we use a syntax like this instead?
if config_max match Some(max) {
println!("The maximum is configured to be {}", max);
}
Yes, That's a very good point. I shouldn't have inverted it. pattern is like a variable and it should be on the left side. Maybe if let
original syntax is not that bad. Anyway some alternatives could be:
if match Some(max) with config_max {}
or
if Some(max) match config_max {}
or
if Some(max) matches config_max {}