The only difference between these two examples is that the first has an &
in &[1, 2, 4]
. Both examples work. I tried to find documentation for this reason but haven't found any yet. What is the reason here? Links to documentation would be appreciated.
Example 1:
fn main() {
let x = &[1, 2, 4];
let mut iterator = x.iter();
assert_eq!(iterator.next(), Some(&1));
assert_eq!(iterator.next(), Some(&2));
assert_eq!(iterator.next(), Some(&4));
assert_eq!(iterator.next(), None);
println!("Ok.");
}
Example 2:
fn main() {
let x = [1, 2, 4];
let mut iterator = x.iter();
assert_eq!(iterator.next(), Some(&1));
assert_eq!(iterator.next(), Some(&2));
assert_eq!(iterator.next(), Some(&4));
assert_eq!(iterator.next(), None);
println!("Ok.");
}