The way method resolution works in Rust is specified in this section of the reference.
For a given type T where a method is being called, it follows these steps:
- Start with a candidate list containing only
T(candidates := [T]) - Try to dereference (
*) the last element of the list(last) - If
*lastis valid, add it to the list (candidates := candidates : [last]) and go to the previous step. Else continue. - AAttempt unsized coercion, meaning vaguely, converting a sized type to its unsized variant (e.g.
[T; N]to[T]) - For each element
toncandidatesadd&tand&mut t - For each
tincandidates: