« first day (2901 days earlier)      last day (592 days later) » 

6:53 AM
@EnnMichael Could you elaborate? I don't see the problem with async quite yet?
 
 
2 hours later…
9:20 AM
There's this neat thing: https://rust-lang.github.io/impl-trait-initiative/explainer/tait.html, which could provide a natural solution for async traits so that boxing is no longer required.

However, there's one small syntactical issue with it: in `impl`s, people would have to write

```
fn f(&self) -> Self::AssociatedFuture {
async { ...actual implementation... }
}
```

I.e. we're back to rust without `async fn`.

Funny enough, this problem could have been solved by taking the TypeScript approach: had we originally said that every `async fn` has to return an `impl Future` type (instead of
Unless there's some nice solution I'm missing
 
I went through the Rust book and got basic knowledge. I would like to start doing some real world projects so I can learn more. Currently I'm a Full stack engineer. Any leads will be appreciated
 
9:52 AM
While TAIT may be interesting on its own, I do not think TAIT "solves" boxing.

When using `AsyncIterator` as a generic parameter, the exact type of the returned future (and its size) is known at compile-time. Things are great.

The problem occurs when using a `dyn AsyncIterator`, base on the (unknown) implementation, the exact type of the return future (and its size) varies. This in turn means that it's not possible to know how much space to reserve on the stack, or in the implicitly generated generator (where it may live as a field).
 
10:48 AM
The problem occurs when using a `dyn AsyncIterator`

But as you said, so long as you can use generic parameters, you can avoid `dyn` entirely. In Rust today, if you want to write traits with async methods and use them to constrain generic parameters, the implementors of these traits are going to have to do boxing. (They could instead implement the associated `Future` type manually, but this is a nightmare)
With TAIT, the implementors no longer have to write the associated future manually nor do they have to resort to boxing
But instead, they have to resort to a slight awkwardness in syntax where instead of async fn they have to use async blocks. And it's not that big of a deal, but it does feel like this solution is "rough around the edges"
@MatthieuM. This is what I'm talking about: play.rust-lang.org/…
```
type Fut = /* The easiest solution is to use a boxed future, Box<dyn Future> or some equivalent syntax sugar like async_trait */;
```

With TAIT, you could just say `type Fut = impl Future<Output = ()>` and let the compiler infer this to be the existential type returned by `f`.
 
 
1 hour later…
12:08 PM
@EnnMichael The problem I am pointing out is that with a dyn MyAsyncTrait, there is NO SINGLE existential type returned by f: each implementation has a different one, and there a caller of dyn MyAsyncTrait cannot know what the size of the implementation it receives will be.
 
12:37 PM
@MatthieuM. Yes, and that's completely different than the issue I'm describing. If you have a trait with an associated type, that type has to have a known size.
The issue I'm describing is that there is no easy way to have this associated type be inferred automatically. Unless you have TAITs.
@MatthieuM. How much have you used async Rust and have you ever used async_trait?
 
Ah, my bad. I thought you were talking about the recent spree of blog posts that Niko has been on, about how to handle the issue of `dyn AsyncIterator` having an unsized associated future type.

In this serie, it was assumed that `impl Future` could be used in return position in a trait, so I was failing to see what the complaint was about.
On the other hand, I guess it's good news regarding your complaint, since it's taken for granted that TAIT will be implemented (to some degree) in the near-future.
It's not really a matter of later features not being as nice, and more one of work being needed still.
 
Yeah, sorry. The complaint is a bit silly. The complaint is that with TAITs, you can do this:

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=587618f9c2116fb1db74877e1050e8e3

And what I dislike is that you have to use an `async` block instead of an `async fn`. We're back to async blocks inside regular functions like in old Rust, which feels a bit annoying.
 
12:52 PM
By the way, you can avoid boxing using "inline" boxes, such as StackFuture: https://github.com/microsoft/stackfuture.

Long term, I hope the Storage proposal allows writing `Box<dyn Future<...>, InlineStorage<...>>` rather than relying on a third-party crate.
 

« first day (2901 days earlier)      last day (592 days later) »