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

(edge-http) Server non-static handler #40

Merged
merged 2 commits into from
Nov 4, 2024
Merged

Conversation

ivmarkov
Copy link
Owner

@ivmarkov ivmarkov commented Nov 3, 2024

(
This change is long overdue and I was delaying it in the (now lost) hope that eventually, the server Handler can become compatible with the nightly AsyncFn closures.

Well, it cannot, and there is no way it could, because AsyncFn closures - just like regular ones - cannot be generic over their parameters, which is a road blocker.

If it is not clear, our handler needs to be generic over the socket type T, and I don't see any way around that.
)

Putting aside this ^^^ topic, what this PR does is to move the generics (including the problematic 'b lifetime generic) to the Handler::handle method, instead of having these on the Handler trait itself.

This is necessary, or else - as is the case in the current code - we need at a few places to put for<'t> type constraints - which - rather than having the desired effect of "for any lifetime" are instead seemingly ending up requiring the lifetime to be equal to 'static.

I'm not sure, but I think this might be another occurrence of this problem.

The PR is much noisier as it also contains a change to suppress the Clippy complaints for us using an unnecessary named lifetime parameter 'b where we can get-by with just '_.

@ivmarkov
Copy link
Owner Author

ivmarkov commented Nov 3, 2024

@AnthonyGrondin FYI if you are using/implementing the Handler trait, there is an adjustment to its signature that you need to do. Nothing super-major though, and I wonder how the current handler signature is actually not affecting you in the first place?

@AnthonyGrondin
Copy link
Contributor

The current handler situation is affecting me in the sense that I need static lifetimes, on anything that passes to the handler. For example, this currently makes it so that I have to statically borrow peripherals if I run the server in a loop, because it could be borrowed on the previous iteration.

See: esp-rs/esp-mbedtls#46 (comment)

@ivmarkov
Copy link
Owner Author

ivmarkov commented Nov 3, 2024

The current handler situation is affecting me in the sense that I need static lifetimes, on anything that passes to the handler. For example, this currently makes it so that I have to statically borrow peripherals if I run the server in a loop, because it could be borrowed on the previous iteration.

See: esp-rs/esp-mbedtls#46 (comment)

Hm, not sure that the existing handler does enforce 'static on anything but the edge-nal traits and thus on the embassy-net types.

But perhaps you can try this branch here if it solves the problem for you? It definitely does for me, as now I can use non-static edge-nal and embassy-net types.

@ivmarkov ivmarkov changed the title (edhe-http) Server non-static handler (edge-http) Server non-static handler Nov 3, 2024
@AnthonyGrondin
Copy link
Contributor

I can confirm this fixes the issues for me. I updated what I've been working on with esp-mbedtls locally, and I can use the server without requiring static lifetimes. I can also mutably borrow in a loop without triggering a lifetime issue.

I've looked at the changes, and it's mostly generics / lifetime changes, and other metaprogramming markers, rather than logic changes so it LGTM.

@ivmarkov ivmarkov merged commit 722f92a into master Nov 4, 2024
1 check passed
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