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

Allow in-place unwrapping of future::Ready #2055

Merged
merged 2 commits into from
Jan 29, 2020
Merged

Allow in-place unwrapping of future::Ready #2055

merged 2 commits into from
Jan 29, 2020

Conversation

tyranron
Copy link
Contributor

This PR adds into_inner method for future::Ready.

Motivation

Due to lack of supporting async fn or impl Trait in traits at the moment, there are a lot of situations we are made to introduce redundant boxing just for "things to work".

impl<T> SomeTrait for AnotherType<T> 
where 
    T: SomeTrait<Future = future::Ready<u8>> ,
{
    type Future = LocalBoxFuture<'static, u32>;

    fn do_some(&self) -> Self::Future {
        self.0.do_some().map(|v| u32::from(v) + 32).boxed_local()
    }
}

But if we know the concrete Future's type being future::Ready, we could have been able to avoid this redundant boxing if we have direct access to the inner immediately ready value:

impl<T> SomeTrait for AnotherType<T> 
where 
    T: SomeTrait<Future = future::Ready<u8>> ,
{
    type Future = future::Ready<u32>;

    fn do_some(&self) -> Self::Future {
        future::ready(self.0.do_some().into_inner().into() + 32)
    }
}

@cramertj
Copy link
Member

Looks reasonable to me!

@cramertj cramertj merged commit b34bdf2 into rust-lang:master Jan 29, 2020
@tyranron tyranron deleted the allow-unwrap-ready-future branch January 29, 2020 18:57
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 this pull request may close these issues.

2 participants