Trouble understand the need to borrow a static vector


I’m having trouble understanding the need to borrow a static vector, such as in the following code:

		for t in &[Module::Diagnosis, Module::Laboratory, Module::Samples, Module::Molecules] {
			if *t != self.players[0].target {

Why do I need to do &[...] as opposed to just [...]? In this case the Module enum implements Copy, so I was assuming it would just take a copy of the values.


This is called an array, [T; 4], not a Vec<T>. The main problem here is that arrays do not implement IntoIterator yet, and probably won’t until we have const generics. However &[T; 4] does implement IntoIterator, treating it the same as a slice &[T] by creating a std::slice::Iter.


What you can do (maybe view as better to read) is pattern matching;

for &t in ...