-
Notifications
You must be signed in to change notification settings - Fork 125
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
Async borrowing (continuation of #449) #450
Conversation
Codecov Report
@@ Coverage Diff @@
## master #450 +/- ##
==========================================
+ Coverage 84.10% 84.48% +0.38%
==========================================
Files 110 110
Lines 5473 5556 +83
==========================================
+ Hits 4603 4694 +91
+ Misses 870 862 -8
Continue to review full report at Codecov.
|
I've tried making this work for an async function of |
Looks like this would not work without impl<T, E> IntoResponse for Result<T, E> where
T: IntoResponse,
E: IntoResponse,
{ ... } which means that returning |
As far as I understand rust uses |
Not exactly. Rust can handle inference like "there's an Ok being returned, so this is a Result, and the only impl for a Result is an impl for I'd also like to say that the mentioned impl looks wrong in my opinion. If I returned an |
What is the status of this pull request? #438 has finally been merged, so this PR should no longer be blocked on it. |
Will rebase in a couple days (maybe faster if the rebase is easy). IIRC, there's the problem that two different variants allow either borrowing (and passing an async function) in async or passing a closure (but no borrowing), not both. |
…n't escape the closure"
This change is important for two reasons. First, it allows the async handler to take the body (or other data) from State. Second, a mutable reference, unlike a shared one, can be Send without State being Sync (which it is not).
These are required on the handler factory (NewHandler impl), but not on the handler itself.
The success path can return not only a response but also anything that implements IntoResponse.
Split the impl into the new handler marker trait and the actual impl using it.
I will admit that I've stepped away from both of these projects, but I occasionally get notifications from both projects, so I'm leaving this here in case it provides inspiration for anyone who comes along. The people over at the goose project seem to have made some headway with closures. Last I saw, they ask the user to wrap the closure in an Arc and Box::pin() the resulting future themselves (the Arc is goose-specific, because of how the containing struct derives Clone. Gotham could probably use Box there too. See https://github.com/tag1consulting/goose/pull/120/files#diff-1cd6d8660ef657deb6ee2a73b4d592d9R1922-R1926 https://github.com/tag1consulting/goose/pull/120/files#diff-8484c6c853111ca2278cc1dc616df376R189-R195 and https://github.com/tag1consulting/goose/pull/126/files) but there might have been some ergonomics improvements since then that I've not been keeping on top of (I'm not sure whether this approach went anywhere, for example: tag1consulting/goose#94 (comment) . I suspect not). I suspect that supporting closures is more interesting for goose than it is for gotham. If the ergonomics of some theoretical |
66f04ce
to
73f4ed1
Compare
Great job! thanks! |
It seems to work as expected.
Todo:
into_handler_error
before?
Feedback needed:
R: IntoResponse
? Yes.&State
or&mut State
? Not really.And "do we want that" for every question above :-)