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

Introduce as_box #981

Closed
Ekleog opened this issue Apr 21, 2018 · 2 comments
Closed

Introduce as_box #981

Ekleog opened this issue Apr 21, 2018 · 2 comments

Comments

@Ekleog
Copy link

Ekleog commented Apr 21, 2018

(whoops, pressing “enter” in the title bar apparently sends the issue, sorry for the blank mail)

I was just thinking that having Box<Either<Foo, Bar>> was inefficient in two ways: first, it allocates, and then on each poll it does a conditional jump for the Either. So I was thinking that it would be possible to introduce as_box as a method on the Future trait, with the obvious default implementation as_box(self) -> Box<Future> { Box::new(self) }, but that could be overridden by eg. Either to actually perform the Either unwrapping immediately, and actually generate either Box or Box.

Not sure that'd bring much, just dropping an idea :)

Anyway, thanks for your work!

@daboross
Copy link

daboross commented May 6, 2018

I think this would suffer from the same problems the old .boxed() method suffered from. Specifically, there's a large ambiguity whether we want to create Box<Future + Send + 'static> or just Box<Future + 'static> (see #228).

Maybe this would be different with the new tokio design? I'm not sure.

@Ekleog
Copy link
Author

Ekleog commented May 6, 2018

Hmm indeed, sounds like it'd be a bad idea for API design reasons, all that for likely-minor performance gain. Thanks! :)

@Ekleog Ekleog closed this as completed May 6, 2018
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

No branches or pull requests

2 participants