Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created December 11, 2018 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rust-play/bf246237cf1aecd49f285bfeb671636d to your computer and use it in GitHub Desktop.
Save rust-play/bf246237cf1aecd49f285bfeb671636d to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
// 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