What is (&v) actually doing in this code?

let v = vec!["hello", "viktor"]; let mut iterator = (&v).into_iter(); // Iter<&str> 
let mut iterator = &v.into_iter(); // &IntoIter<&str> 

How it is changing what is returned from .into_iter(). Why is the result different?

1

1 Answer

This is a precedence issue. With &v.into_iter(), the compiler understands &(v.into_iter()) not (&v).into_iter(), just like when you write 1+2*3, the compiler understands 1+(2*3), and not (1+2)*3.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.