Skip to content

Instantly share code, notes, and snippets.

@egroj97
Created July 28, 2019 02:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save egroj97/c5e8551e7128bc9f9db19113ef1689b3 to your computer and use it in GitHub Desktop.
Save egroj97/c5e8551e7128bc9f9db19113ef1689b3 to your computer and use it in GitHub Desktop.
fn main() {
// Variables can be type annotated.
let logical: bool = true;
let a_float: f64 = 1.0; // Regular annotation
let an_integer = 5i32; // Suffix annotation
// Or a default will be used.
let default_float = 3.0; // `f64`
let default_integer = 7; // `i32`
// A type can also be inferred from context
let mut inferred_type = 12; // Type i64 is inferred from another line
inferred_type = 4294967296i64;
// A mutable variable's value can be changed.
let mut mutable = 12; // Mutable `i32`
mutable = 21;
// Error! The type of a variable can't be changed.
mutable = true;
// Variables can be overwritten with shadowing.
let mutable = true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment