fork download
  1. fn main() {
  2. let mut a = vec![3, 3, 4];
  3. println!("a = {:?}", a);
  4. let mut b: Vec<_> = (0..(10_i64 + 1))
  5. .filter(|&i| i % 2 == 0)
  6. .map(|i| i.pow(2))
  7. .collect();
  8. println!("b = {:?}", b);
  9. let mut c = vec![];
  10. println!("{:?}", c);
  11. let cardinality = a.len();
  12. println!("cardinality = {}", cardinality);
  13. let second_element = a[2];
  14. println!("second_element = {}", second_element);
  15. for &x in &a {
  16. println!("{}", x);
  17. }
  18. let num_of_three = a.iter()
  19. .filter(|&&x| x == 3)
  20. .count();
  21. println!("num_of_three = {}", num_of_three);
  22. a[2] = 3;
  23. println!("a = {:?}", a);
  24. c.push(42);
  25. println!("c = {:?}", c);
  26. let tail = b.pop().unwrap();
  27. println!("tail = {}", tail);
  28. println!("b = {:?}", b);
  29. }
Success #stdin #stdout 0s 4232KB
stdin
Standard input is empty
stdout
a = [3, 3, 4]
b = [0, 4, 16, 36, 64, 100]
[]
cardinality = 3
second_element = 4
3
3
4
num_of_three = 2
a = [3, 3, 3]
c = [42]
tail = 100
b = [0, 4, 16, 36, 64]