futures-rs icon indicating copy to clipboard operation
futures-rs copied to clipboard

Add `BoxTryFuture` and `BoxTryStream` aliases

Open Velnbur opened this issue 1 year ago • 3 comments

BoxFuture and TryFuture are already in lib, but why not BoxTryFuture? The same goes for BoxTryStream and TryStream. I'm declaring both of them quite often, maybe I'm not alone with this problem, so why not add them to futures after all?

Velnbur avatar Jul 12 '24 13:07 Velnbur

It's quite popular I would say: https://github.com/search?q=BoxTryFuture&type=code

Velnbur avatar Jul 12 '24 13:07 Velnbur

It's quite popular I would say: https://github.com/search?q=BoxTryFuture&type=code

Only 4 seem to be unique (tide, tinychain, txn_lock, tokio-tide, and tokio-tide's code is in comment). All the others seem to be forks of tide and tinychain.

taiki-e avatar Jul 12 '24 13:07 taiki-e

You're right. So you consider this extra for now? I still think that this is quite useful.

Also, the search can be extended by looking for the usage of BoxFuture<Result*.

I can see that the usage of BoxTryFuture<Ok, Err> instead of BoxFuture<Result<Ok, Err>> could be controversial. Especially in cases when Error is hidden in a type alias like BoxFuture<Result<Ok>>, because for someone the last one is more convenient. But refactoring this:

async fn get<'a>(&'a self) -> BoxStream<'a,  Result<BoxFuture<'a, Result<T, Error>>, Error>> {

to this:

type ItemStream<'a, T, Err> = BoxTryStream<'a,  BoxTryFuture<'a, T, Err>, Err>>;

async fn get<'a>(&'a self) -> ItemStream<'a, T, Error> {

made my day :)

Velnbur avatar Jul 12 '24 14:07 Velnbur