Guest User

Untitled

a guest
Jun 22nd, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. fn main() {
  2.  
  3. // WILL COMPILE BECAUSE VALUE IS KNOWN AT COMPILE TIME
  4. const MAX_POINT : i32 = 500;
  5.  
  6. //WILL NOT COMPILE BECAUSE value can not be calculated at compile-time in stable
  7. //although note: a limited form of compile-time function evaluation is available
  8. //on a nightly compiler via `const fn`
  9. const CALC_MAX_POINT : i32 = calculate_max_point(32);
  10. }
  11.  
  12. fn calculate_max_point(val : i32) -> i32 {
  13. val * 2
  14. }
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42. // Hint: The declaration on line 5 is missing a keyword that is needed in Rust
  43. // to create a new variable binding.
Add Comment
Please, Sign In to add comment