Update Examples

Glen Whitney 2024-08-27 02:37:58 +00:00
parent dec41efd58
commit 8e5ef3d743

@ -1189,19 +1189,20 @@ fn main
let vec1 = vec![1, 2, 3] let vec1 = vec![1, 2, 3]
vec2 = vec![4, 5, 6] vec2 = vec![4, 5, 6]
println! "2 in vec1: {}", vec1.iter() .any(|&x| x == 2)); //! Note use of fragment of loop construct to just get the corresponding iterator
println!("2 in vec2: {}", vec2.into_iter().any(|x| x == 2)); println! "2 in vec1: {}", &in vec1.any &x => x == 2
println! "2 in vec2: {}", in vec2.any x => x == 2
println!("vec1 len: {}", vec1.len()); println! "vec1 len: {}", vec1.len()
println!("First element of vec1 is: {}", vec1[0]); println! "First element of vec1 is: {}", vec1[0]
// `into_iter()` does move `vec2` and its elements, so they cannot be used again // `into_iter()` does move `vec2` and its elements, so they cannot be used again
let array1 = [1, 2, 3]; let array1 = [1, 2, 3]
let array2 = [4, 5, 6]; array2 = [4, 5, 6]
println! "2 in array1: {}", &in array1.any &x => x == 2
println!("2 in array2: {}", in array2.any x => x == 2
println!("2 in array1: {}", array1.iter() .any(|&x| x == 2));
println!("2 in array2: {}", array2.into_iter().any(|x| x == 2));
}
``` ```
</td></tr></table> </td></tr></table>