Two references to the same vector



examples/vectors/two-references-to-the-same-vector/src/main.rs
#[derive(Debug)]
#[allow(dead_code)]
struct Something {
    number: i32,
    text: String,
    numbers: Vec<i32>,
}

fn main() {
    let va: Vec<Something> = vec![
        Something {
            number: 1,
            text: String::from("small"),
            numbers: vec![1, 2, 3],
        },
        Something {
            number: 11,
            text: String::from("medium"),
            numbers: vec![11, 12],
        },
        Something {
            number: 101,
            text: String::from("large"),
            numbers: vec![101],
        },
    ];
    println!("{:#?}", va);

    let vb = &va; // use & to borrow
    println!("{:#?}", vb);
    println!("{:#?}", va);
}

[
    Something {
        number: 1,
        text: "small",
        numbers: [
            1,
            2,
            3,
        ],
    },
    Something {
        number: 11,
        text: "medium",
        numbers: [
            11,
            12,
        ],
    },
    Something {
        number: 101,
        text: "large",
        numbers: [
            101,
        ],
    },
]
[
    Something {
        number: 1,
        text: "small",
        numbers: [
            1,
            2,
            3,
        ],
    },
    Something {
        number: 11,
        text: "medium",
        numbers: [
            11,
            12,
        ],
    },
    Something {
        number: 101,
        text: "large",
        numbers: [
            101,
        ],
    },
]
[
    Something {
        number: 1,
        text: "small",
        numbers: [
            1,
            2,
            3,
        ],
    },
    Something {
        number: 11,
        text: "medium",
        numbers: [
            11,
            12,
        ],
    },
    Something {
        number: 101,
        text: "large",
        numbers: [
            101,
        ],
    },
]