The iter() method can cause confusion when being called on array objects.
Because of Rust's expression resolution ordering, an array does not natively implement the iter() method. Instead, that function is implemented on slices. Because of this, calling iter() on an array will find Miniconf::iter() instead of trying to convert the array to a slice and then looking up functions.
In this case:
Rust fails to find the iter() method on the array object because it indeed has no iter() function.
Rust looks at trait impls for iter() on the array object. In our case, it finds iter() because of trait Miniconf and uses that
However, this may be undesirable because the user might be trying to coerce the array object into a slice to call the slice iterator method. Because of the resolution ordering, the Miniconf iter() method is selected instead.
The workaround for this defect is to first explicitly convert the array object into a slice as follows:
The
iter()
method can cause confusion when being called on array objects.Because of Rust's expression resolution ordering, an array does not natively implement the
iter()
method. Instead, that function is implemented on slices. Because of this, callingiter()
on an array will findMiniconf::iter()
instead of trying to convert the array to a slice and then looking up functions.In this case:
iter()
method on the array object because it indeed has noiter()
function.iter()
on the array object. In our case, it findsiter()
because oftrait Miniconf
and uses thatHowever, this may be undesirable because the user might be trying to coerce the array object into a slice to call the slice iterator method. Because of the resolution ordering, the Miniconf
iter()
method is selected instead.The workaround for this defect is to first explicitly convert the array object into a slice as follows:
We likely want to rename the
iter()
method to prevent this confusion in the future.