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

Never vs. PhantomData #32

Closed
cramertj opened this issue Aug 11, 2016 · 3 comments
Closed

Never vs. PhantomData #32

cramertj opened this issue Aug 11, 2016 · 3 comments

Comments

@cramertj
Copy link
Member

cramertj commented Aug 11, 2016

An RFC was recently approved for the ! (Never) type, which represents the type of a value that can never exist.

Several structs in of futures-rs use PhantomData to mark the type of values that can't exist, such as the Error type of Finished, the Item type of Failed, and the Item and Error types of Empty. I believe that, once this PR lands (and then makes its way to stable), these structs should be rewritten to use the Never type. Empty, for example, could be written as follows:

pub struct Empty {}

pub fn empty() -> Empty { // Is this even necessary any more?
    Empty {}
}

impl Future for Empty {
    type Item = !;
    type Error = !;

    fn poll(&mut self, _: &mut Task) -> Poll<Self::Item, Self::Error> {
        Poll::NotReady
    }

    fn schedule(&mut self, task: &mut Task) {
        drop(task);
    }
}

Unfortunately, this feature has yet to land on nightly, let alone stable. Therefore, a transition to Never is likely a ways off. As this library is already getting lots of attention, I believe there should be a plan for how and if to structure the library so that a future (hehe 😃 ) transition to Never is possible.

In order to be more consistent with terminology, I also think that Empty should be renamed to Never. ! is called Never rather than Empty or Void as a result of the discussion at the end of the Never PR. The gist of it is that Empty isn't a future for an Empty value, it's a future for a value that can Never exist (i.e. it Never completes).

P.S. Great work on this library, @alexcrichton & company! I'm excited to use this in my future Rust projects.

@alexcrichton
Copy link
Member

Oh man I'd love to make use of !! This seems like a super slick way to use that type, and I know I personally find it annoying that sometimes I have to specify the other type parameter of failed, empty, etc.

Right now though this library does compile on stable Rust, and I'd personally prefer to require that, but as soon as ! lands on nightly then I'd love to add a nightly feature to this crate which adds versions of these combinators. Eventually once ! is stable we can just deprecate all the old combinators in favor of the ones using !.

How's that sound?

@cramertj
Copy link
Member Author

cramertj commented Aug 11, 2016

Sounds great! I'll keep an eye out on the ! PR and follow up once it lands on nightly.

Did you have any thoughts about changing the name of Empty? Perhaps NeverFuture? I feel a bit anxious about Never since it isn't really equivalent to !-- it's a Future that yields !.

This was referenced Aug 19, 2016
@cramertj
Copy link
Member Author

The ergonomics of this feature didn't work out due to restrictions around default type parameters and missing trait impls for !. I'm closing for now with the intent to reopen later once ! and default type parameters have had a chance to develop.

withoutboats pushed a commit that referenced this issue Mar 25, 2018
#[async_stream] implementation
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