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

Receiver::Error should be something like Never or Nothing #476

Closed
stepancheg opened this issue May 15, 2017 · 12 comments
Closed

Receiver::Error should be something like Never or Nothing #476

stepancheg opened this issue May 15, 2017 · 12 comments

Comments

@stepancheg
Copy link
Contributor

enum Nothing {}

impl Stream for Receiver<T> {
    type Error = Nothing;
}

To clearly state that poll never fails.

@stepancheg
Copy link
Contributor Author

BTW, tokio_core::reactor::Handle::spawn future parameter Error should probably be Nothing too.

@stepancheg
Copy link
Contributor Author

... and Executor impl for CpuPool too.

Currently it has signature

impl<F> Executor<F> for CpuPool
    where F: Future<Item = (), Error = ()> + Send + 'static,

Which gives user false sense that it is OK to return error. While it is not, error must be handled inside the future.

@srijs
Copy link
Contributor

srijs commented Jul 9, 2017

FWIW Elm uses Never as the name for this type, to signify that a certain task for instance can "never" fail. I always thought that particular name worked quite well.

@jimmycuadra
Copy link
Contributor

When it's eventually stable, the never type (!) would be ideal for this.

@alexcrichton
Copy link
Member

I wrote in #554:


Right now there's a number of locations in this library where () is used as an error type

I've also heard of this being common enough throughout the ecosystem that I think we should provide a solution to this! I think we'll want to not "just add a Void" type but also make sure it's at least reasonably ergonomic to use. For example I think we should add:

enum Void {}
Void::into(self) -> T
Future<Item=T, Error=Void>::poll_ok(&mut self) -> Async<T>
Future<Item=T, Error=Void>::wait_ok(self) -> T

And maybe more! I'm curious to hear what others think about adding such APIs.

@alexcrichton
Copy link
Member

I wouldn't mind trying to game this out before an 0.2 release. We can't change existing types but we could add the type for external libraries to use, as well as the extra goodies on the Future trait itself!

@jimmycuadra
Copy link
Contributor

Is there no hope of the never type being stabilized in a time frame that would make it reasonable to just wait on this issue rather than introduce a futures-specific void type?

@alexcrichton
Copy link
Member

AFAIK yeah, the stabilization story for ! is quite long-term still

@srijs
Copy link
Contributor

srijs commented Aug 28, 2017

@alexcrichton Are you saying you would consider a PR adding Void to this crate in order for dependent libraries to use, plus a few utilities (converting Future<Error=Void> to any Future<Error=A> comes to mind)? If so, I'd be interested in picking this up.

@alexcrichton
Copy link
Member

Certainly! Unfortunately we can't land a breaking change right now so we can't change the type Error = ();, but we could start paving the road for future implementations!

@rustonaut
Copy link
Contributor

rustonaut commented Mar 6, 2018

@jimmycuadra I havent looked to deep into ! but shouldn't it be possible to use the Never type (which by now is in the tokio 0.2 branch) and once it's stable change Never to wrap ! (i.e. struct Never(!)). I would
guess that should give the same benefit's then directly using ! while keeping backward compability intact (e.g. someone might implement a trait on both Never and ! which "somehow" conflicts with implementing it on !)

@alexcrichton does that mean it will change for the v0.2 release or that it will stay () and just new or otherwise changed API's will get the change?.

I was looking at a not up-to-date version of v0.2, the changes are there by now.
(so this Issue can be closed?)

@aturon
Copy link
Member

aturon commented Mar 19, 2018

This has been done for 0.2.

@aturon aturon closed this as completed Mar 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants