fn read_elements() {
    /*
    two ways to get the third element are by using & and [], which gives us a 
    reference, or by using the get method with the index passed as an argument, 
    which gives us an Option<&T>.
    */
    let v = vec![1, 2, 3, 4, 5];

    let third: &i32 = &v[2];
    println!("read_elements: The third element is {}", third);

    match v.get(2) {
        Some(third) => println!("read_elements: The third element is {}", third),
        None => println!("read_elements: There is no third element."),
    }

    // This will cause the program to panic because it references a nonexistent 
    // element.
    // let does_not_exist = &v[100];

    let does_not_exist = v.get(100);
    println!("In read_elements, does_not_exist is {:?}.", does_not_exist);

    /*
    Recall the rule that states you can’t have mutable and immutable references 
    in the same scope.
    */
    let mut v2 = vec![1, 2, 3, 4, 5];

    #[allow(unused_variables)]
    let first = &v2[0];

    v2.push(6);

    /*
    Uncommenting the next line causes the program to crash. This error is due 
    to the way vectors work: adding a new element onto the end of the vector 
    might require allocating new memory and copying the old elements to the new 
    space, if there isn’t enough room to put all the elements next to each 
    other where the vector currently is. In that case, the reference to the 
    first element would be pointing to deallocated memory.
    */
    // println!("read_elements: The first element is: {}", first);
}
// <- v goes out of scope and is freed here
<- v goes out of scope and is freed here
< - v goes out of scope and is freed here
fn read_elements() {
    /*
    two ways to get the third element are by using & and [], which gives us a 
    reference, or by using the get method with the index passed as an argument, 
    which gives us an Option<&T>.
    */
    let v = vec![1, 2, 3, 4, 5];
    let third: &i32 = &v[2];
    println!("read_elements: The third element is {}", third);
    match v.get(2) {
        Some(third) => println!("read_elements: The third element is {}", third),
        None => println!("read_elements: There is no third element."),
    }
    // This will cause the program to panic because it references a nonexistent 
    // element.
    // let does_not_exist = &v[100];
    let does_not_exist = v.get(100);
    println!("In read_elements, does_not_exist is {:?}.", does_not_exist);
    /*
    Recall the rule that states you can’t have mutable and immutable references 
    in the same scope.
    */
    let mut v2 = vec![1, 2, 3, 4, 5];
    #[allow(unused_variables)]
    let first = &v2[0];
    v2.push(6);
    /*
    Uncommenting the next line causes the program to crash. This error is due 
    to the way vectors work: adding a new element onto the end of the vector 
    might require allocating new memory and copying the old elements to the new 
    space, if there isn’t enough room to put all the elements next to each 
    other where the vector currently is. In that case, the reference to the 
    first element would be pointing to deallocated memory.
    */
    // println!("read_elements: The first element is: {}", first);
}
fn read_elements ( ) { /*
    two ways to get the third element are by using & and [], which gives us a 
    reference, or by using the get method with the index passed as an argument, 
    which gives us an Option<&T>.
    */ let v = vec ! [ 1 2 3 4 5 ] ; let third : & i32 = & v [ 2 ] ; println ! ( " " third ) ; match v . get ( 2 ) { Some ( third ) => println ! ( " " third ) , None => println ! ( " " ) , } // This will cause the program to panic because it references a nonexistent  // element. // let does_not_exist = &v[100]; let does_not_exist = v . get ( 100 ) ; println ! ( " " does_not_exist ) ; /*
    Recall the rule that states you can’t have mutable and immutable references 
    in the same scope.
    */ let mut v2 = vec ! [ 1 2 3 4 5 ] ; # [ allow ( unused_variables ) ] let first = & v2 [ 0 ] ; v2 . push ( 6 ) ; /*
    Uncommenting the next line causes the program to crash. This error is due 
    to the way vectors work: adding a new element onto the end of the vector 
    might require allocating new memory and copying the old elements to the new 
    space, if there isn’t enough room to put all the elements next to each 
    other where the vector currently is. In that case, the reference to the 
    first element would be pointing to deallocated memory.
    */ // println!("read_elements: The first element is: {}", first); }
<- v goes out of scope and is freed here
< - v goes out of scope and is freed here