Why are developers restricted to only using arguments of type i32 for matching with the std::cmp (Comparison and Ordering Module)?
I have tried to be explicit as possible in declaring variables secret_number
and guess
as being of type u64 (unsigned 64 bit integer literal). However, it will not allow me to explicitly define the type of arguments and output to expect from the match cmp
function (i.e. none of the following approaches are allowable: match cmp(guess: u64, secret_number: u64) -> { ...
and Ordering::Less::<u64> => ...
and Ordering::Less -> u64 => ...
)
Given the following code snippet
let secret_number: u64 = (rand::random::<u64>());
let guess: u64 = (rand::random::<u64>());
match cmp(guess, secret_number) {
Ordering::Less => println!("Too small"),
Ordering::Greater => println!("Too big!"),
Ordering::Equal => println!("Win"),
}
Building with Cargo gives the following errors:
src/main.rs:426:13: 426:18 error: mismatched types:
expected `i32`,
found `u64`
(expected i32,
found u64) [E0308]
src/main.rs:426 match cmp(guess, secret_number) {
^~~~~
src/main.rs:426:20: 426:33 error: mismatched types:
expected `i32`,
found `u64`
(expected i32,
found u64) [E0308]
src/main.rs:426 match cmp(guess, secret_number) {
Note that I am running rustc 1.0.0-nightly