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

Support async #1

Open
danielhenrymantilla opened this issue Oct 3, 2020 · 0 comments
Open

Support async #1

danielhenrymantilla opened this issue Oct 3, 2020 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@danielhenrymantilla
Copy link
Owner

While the crate currently supports most control-flow interacting effects, such as break, continue, (early) return and ?, there is still one special control-flow transformation that needs to be supported: async / .await.

That is,

#[with]
async fn foo (...) -> Ret<'local>
{
    ...
}

ought to unsugar to something along the lines of:

async fn foo<R> (..., ret: impl for<'local> FnOnce( Ret<'local> ) -> BoxFuture<'local, R>)
  -> R
{
    ...
}
  • Currently, the callback needs to return a dyn Future since otherwise Rust gets confused with HRTB involving a higher-order lifetime, an infinite set of possible impl Futures returned by the callback, and the fact all the futures need to resolve to the same type R, independent of the 'local lifetime.

  • In practice, this requires a helper wrapper around the return value of the callback, since otherwise the for<'any> higher-order bound over restrains in the region of big lifetimes, thus preventing the provided callback / future from borrowing anything, which would totally obliterate the usability and thus purpose of this pattern.

    See this post of mine, especially the Hack wrapper, to better see why.

  • Finally, it would be neat if the dyn Future relied on a stack allocation of some form rather than a heap-allocation: Pin<&'local mut dyn Future>

@danielhenrymantilla danielhenrymantilla self-assigned this Oct 3, 2020
@danielhenrymantilla danielhenrymantilla added the enhancement New feature or request label Oct 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant