I could understand it if count_zeros took a &self, so Rust has to dereference it before invoking the method, but in this case it takes a self and the binding foo is not a reference, so why it is working?
Actually I came to this question since I was trying to dig into Iterator traits, and I've noticed that Vec<T> doesn't implement directly Iterator<T>, but indirectly via Deref<Target=[T]>.
I've already read this part of the book, but I think I missing something.
It's written that:
If you have a type U, and it implements Deref<Target=T>, values of &U will automatically coerce to a &T
So since in my example there are no references this rule shouldn't be applied, right?
The other rule is about method call and it basically says (correct if I am wrong) that Rust will apply as many * as needed in order to match the method signature (for the self parameter). In my example no * are needed since the method signature matches already the method call. I am calling the method passing self and the method takes a self.
So, this mean that in my example Rust automatically put *& before my foo binding? So something like this:
(*(&(foo)).count_zeros();
Ok, now it is more clear.
Anyway in my opinion, maybe in the new version of the book, it should explained better which is the algorithm used by Rust to match method call. I will check it and in case try to suggest a deeper explanation.