Skip to content

Removed 'static bound requirements for the lambda_http crate and create a shared resources example for the crate #333

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

Merged
merged 2 commits into from
Jul 8, 2021

Conversation

coltonweaver
Copy link
Contributor

Following discussion in #310, it makes sense to include these changes in the lambda_http crate as well. I've given this work a pass, and am looking for feedback now.

Issue #, if available: #310

Description of changes:

  • Added explicit lifetime bounds on each of the handler and adaptor types in the lambda_http crate, so we don't have to rely on the futures for these being 'static any longer.
  • Added an example of how one might use this to the examples folder. Have tested that these changes work in the Lambda console with an APIGW event:
Response
{
  "statusCode": 200,
  "headers": {},
  "multiValueHeaders": {},
  "body": "f9b73b61-82cf-4da5-b084-19f01ee76346: Client (random_client_name_1) invoked by Colton.",
  "isBase64Encoded": false
}

The request was a regular APIGW proxy event with the query string value "first_name" set to my name.

By submitting this pull request

  • [ X] I confirm that my contribution is made under the terms of the Apache 2.0 license.
  • [ X] I confirm that I've made a best effort attempt to update all relevant documentation.

pub fn handler<'a, H: Handler<'a>>(handler: H) -> Adapter<'a, H> {
Adapter {
handler,
_pd: PhantomData,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give more context on what this is for? I'm not sure I understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, if you look down below it's because I added the explicit lifetime to the Adapter struct, because it holds a Handler that requires a lifetime parameter. Because the 'a lifetime is unused in Adapter, otherwise, the compiler complains about the unused lifetime parameter we supplied to it. The PhantomData is just a zero-sized compiler dummy value that holds the 'a lifetime and "uses" the lifetime to make the compiler happy.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, okay. That makes sense now thank you.

@coltonweaver coltonweaver merged commit 797f0ab into master Jul 8, 2021
@nmoutschen nmoutschen deleted the cbweaver-http-static-bounds branch February 1, 2022 08:27
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