Member-only story
Running this will show incompatible error type which is interesting. Guess why?
Because the value of if condition is int type but in else is string type.
error[E0308]: `if` and `else` have incompatible types
--> src/main.rs:6:9
|
3 | let number = if condition {
| __________________-
4 | | 5
| | - expected because of this
5 | | } else {
6 | | "six"
| | ^^^^^ expected integer, found `&str`
7 | | };
| |_____- `if` and `else` have incompatible types
Change to this :
Will succeed.
Compiling rust-getstarted v0.1.0 (/home/cuongld/GolandProjects/rust-getstarted)
Finished dev [unoptimized + debuginfo] target(s) in 0.24s
Running `target/debug/rust-getstarted`
The value of number is: 8
~~Happy coding~~~