On why await shouldn't be a method

But then that defeats the whole purpose of making it a trait method.

The reason for making it a trait method is to make it less magic, because it's just a normal method. So because it's a normal method, people don't need to learn anything new, and it doesn't require new syntax, etc.

But if you're now saying, "well, it's like a normal method, except not in these cases" people will wonder "why?" and then you have to explain that it's not really a method, it's actually special compiler magic.

Then people will ask "then why is it a method on a trait, if it's not actually a method on a trait?"

You cannot use the Await trait in bounds. You cannot use Await::await. So why is it being implemented as a trait method, if it never behaves like a trait method?

If the only valid thing you can do is foo.await(), then that's not a trait method, that's just new syntax!

Basically, you're introducing a huge amount of extra complexity for no benefit at all.

If you want foo.await() syntax, that's fine, but there's no need to introduce magic trait methods, it can just be new syntax.

Does it? Could you give an example of where such a restriction exists?

With generators, yield is a keyword, not a trait method, so the whole issue of "what does foo.map(yield) mean?" never comes up.

Using async does not create a special kind of function.

If you use async fn, it creates a normal function, which returns impl Future. You can use that function anywhere that a normal function can be used. It's not special or different.

The same is true for generators, which create a normal function which returns impl Iterator.

5 Likes