Advertisement
cwchen

[Rust] Array limitation issue with size.

Aug 22nd, 2017
720
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.36 KB | None | 0 0
  1. extern crate rand;
  2.  
  3. use rand::Rng;
  4.  
  5. fn main() {
  6.     const SIZE: usize = 33;  // Watch out when SIZE > 32
  7.     const MIN: i32 = 1;
  8.     const MAX: i32 = 100;
  9.  
  10.     let mut array: [i32; SIZE] = [0; SIZE];
  11.  
  12.     for i in 0..SIZE {
  13.         array[i] = rand::thread_rng().gen_range(MIN, MAX + 1);
  14.     }
  15.  
  16.     println!("{:?}", array);  // Error when SIZE > 32
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement