Created
November 3, 2014 16:21
-
-
Save garrickp/3b87852257f6cced56a6 to your computer and use it in GitHub Desktop.
Comparison not working
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Ordering { | |
Less, | |
Equal, | |
Greater, | |
} | |
fn cmp(a: int, b: int) -> Ordering { | |
if a < b { Less } | |
else if a > b { Greater } | |
else { Equal } | |
} | |
fn main() { | |
let x = 5i; | |
let y = 6i; | |
let ordering = cmp(x, y); | |
if ordering == Less { | |
println!("less"); | |
} else if ordering == Equal { | |
println!("equal"); | |
} else { | |
println!("greater"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vagrant@vagrant-ubuntu-trusty-64:/vagrant/projects/hello_world$ cargo build && ./target/hello_world | |
Compiling hello_world v0.0.1 (file:///vagrant/projects/hello_world) | |
/vagrant/projects/hello_world/src/main.rs:19:5: 19:21 error: binary operation `==` cannot be applied to type `Ordering` | |
/vagrant/projects/hello_world/src/main.rs:19 if ordering == Less { | |
^~~~~~~~~~~~~~~~ | |
/vagrant/projects/hello_world/src/main.rs:21:12: 21:29 error: binary operation `==` cannot be applied to type `Ordering | |
/vagrant/projects/hello_world/src/main.rs:21 } else if ordering == Equal { | |
^~~~~~~~~~~~~~~~~ | |
error: aborting due to 2 previous errors | |
Could not compile `hello_world`. | |
To learn more, run the command again with --verbose. | |
vagrant@vagrant-ubuntu-trusty-64:/vagrant/projects/hello_world$ rustc --version | |
rustc 0.13.0-nightly (b87619e27 2014-11-02 23:27:10 +0000) |
geraldstanje
commented
Nov 3, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment