Currently, APIs are often forced to either (1) expose a concrete return type or (2) return trait objects, which come with several downsides.
For example, the iter
function for Vec<T>
currently has the signature
fn iter<'a>(&'a self) -> Items<'a, T>
where Items
is a struct defined purely for iterating over a slice. The struct has no public fields; the only interesting thing about it is that it implements various traits, such as Iterator<&'a T>
.
This API is revealing more than it might have to: the type Items
should not have to be exposed at all. Instead, we should be able to give iter
a signature like: