Variable Bindings

Rust provides type safety via static typing. Variable bindings can be type
annotated when declared. However, in most cases, the compiler will be able
to infer the type of the variable from the context, heavily reducing the
annotation burden.

Values (like literals) can be bound to variables, using the let binding.

  1. fn main() {
  2. let an_integer = 1u32;
  3. let a_boolean = true;
  4. let unit = ();
  5. // copy `an_integer` into `copied_integer`
  6. let copied_integer = an_integer;
  7. println!("An integer: {:?}", copied_integer);
  8. println!("A boolean: {:?}", a_boolean);
  9. println!("Meet the unit value: {:?}", unit);
  10. // The compiler warns about unused variable bindings; these warnings can
  11. // be silenced by prefixing the variable name with an underscore
  12. let _unused_variable = 3u32;
  13. let noisy_unused_variable = 2u32;
  14. // FIXME ^ Prefix with an underscore to suppress the warning
  15. }