创建 vector

    1. let v: Vec<i32> = Vec::new();
    2. let v = vec![1, 2, 3];

    更新 vector

    1. let mut v = Vec::new();
    2. v.push(5);
    3. v.push(6);
    4. v.push(7);
    5. v.push(8);

    读取 vector

    1. let v = vec![1, 2, 3, 4, 5];
    2. let third: &i32 = &v[2];
    3. println!("The third element is {}", third);
    4. match v.get(2) {
    5. Some(third) => println!("The third element is {}", third),
    6. None => println!("There is no third element."),
    7. }

    遍历 vector

    1. let v = vec![100, 32, 57];
    2. for i in &v {
    3. println!("{}", i);
    4. }
    5. let mut v = vec![100, 32, 57];
    6. for i in &mut v {
    7. *i += 50;
    8. }

    使用枚举来储存多种类型

    1. enum SpreadsheetCell {
    2. Int(i32),
    3. Float(f64),
    4. Text(String),
    5. }
    6. let row = vec![
    7. SpreadsheetCell::Int(3),
    8. SpreadsheetCell::Text(String::from("blue")),
    9. SpreadsheetCell::Float(10.12),
    10. ];