If we have a function foo
this would have foo
as the name of it’s type. This would allow us to name things that we can’t currently name, one example of this is Map<slice::Iter<T>, foo>
for the result of calling map(foo)
on a slice::Iter<T>
where foo
is a function taking &T
. To me it is quite intuitive what foo
means here (I actually tried doing this when I was learning rust).
This would not be a backwards compatible change. However because functions use snake_case
and types use CamelCase
I don’t think we would have a lot of breakage.
Currently you would have to have a function and a type with the same name and ignore the lint that says you do not follow the naming convention for this change to break anything.
The only big things that we still can’t directly name with this change are closures, return types of functions with impl Trait
, and in the future return types of async functions. A lot of times a closure can be changed to a function (if it does not capture anything) and impl Trait
and async will be namable using existential types. Another benefit of this is that we can immediately get the output of foo
using foo::Ouput
because it implements the Fn
traits. This is another problem that came up with async functions.
An instance where this would be useful is a struct where it’s Iterators can be expresed as abother iterator with some functions called on in. This is why I chose Map
as the example above, you could have some struct Iter { inner: Map</**/, foo> }
and implement traits by delegating.