Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BoxTryFuture and BoxTryStream aliases #2869

Open
Velnbur opened this issue Jul 12, 2024 · 3 comments · May be fixed by #2870
Open

Add BoxTryFuture and BoxTryStream aliases #2869

Velnbur opened this issue Jul 12, 2024 · 3 comments · May be fixed by #2870

Comments

@Velnbur
Copy link

Velnbur commented Jul 12, 2024

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
Copy link
Author

Velnbur commented Jul 12, 2024

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

@Velnbur Velnbur linked a pull request Jul 12, 2024 that will close this issue
@taiki-e
Copy link
Member

taiki-e commented Jul 12, 2024

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.

@Velnbur
Copy link
Author

Velnbur commented Jul 12, 2024

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants