Created
December 11, 2018 17:55
-
-
Save rust-play/bf246237cf1aecd49f285bfeb671636d to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains 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
// type inference | |
fn main() { | |
let val1: u32 = 42; | |
// ^^^ type specified explicitly | |
let val2 = 42; | |
// ^ type inferred | |
let val3: u32 = "42".parse().unwrap(); | |
// ^^^ parse method uses the type for conversion - c++ can't do this | |
let val4 = "42".parse::<u32>().unwrap(); | |
// ^ no type ^^^^^^^ 'turbofish' syntax to mention type | |
println!("val {} {} {} {}", val1, val2, val3, val4); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment