8000 Fix/pagination lifetimes by arlyon · Pull Request #283 · arlyon/async-stripe · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix/pagination lifetimes #283

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

Closed
wants to merge 6 commits into from
Closed

Fix/pagination lifetimes #283

wants to merge 6 commits into from

Conversation

arlyon
Copy link
Owner
@arlyon arlyon commented Oct 29, 2022

Closes #246 which prevents using borrowed params with the paginator api.

Currently planning on reworking this without lifetimes by serializing the params immediately effectively making them owned.

@arlyon arlyon force-pushed the fix/pagination-lifetimes branch 4 times, most recently from a55aaf9 to eb8d09c Compare October 30, 2022 14:16
strategy: &RequestStrategy,
) -> Response<T> {
strategy: &'a RequestStrategy,
) -> Response<'a, T> {
Copy link
Collaborator
@mzeitlin11 mzeitlin11 Oct 30, 2022

Choose a reason for hiding this comment

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

I'm a little confused by the lifetimes here - why is tying the Response lifetime to client lifetime needed? Looks like in the function body the client gets cloned anyway, so could that client just be moved into the future so that no lifetime is needed?

Copy link
Owner Author
@arlyon arlyon Oct 31, 2022

Choose a reason for hiding this comment

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

You are probably correct in questioning this. The PR is a little sloppy at the moment as it took a fair bit of experimentation. Moving it is probably more idiomatic.

@mzeitlin11
Copy link
Collaborator
mzeitlin11 commented Oct 30, 2022

I tried messing around with the lifetimes a bit to avoid the issue mentioned in the comment above but didn't really get anywhere.

Since we end up cloning the pagination params anyway, what about just leaving the 'static lifetime on P and changing the Expand signature? Could use something like Cow<'static, str> if still want to support 'static str without allocation.

EDIT: some more general thoughts/ideas below

@mzeitlin11
Copy link
Collaborator
mzeitlin11 commented Oct 30, 2022

Generally a bit wary of the added lifetime parameters, with the example in the comment around execute. The extra complexity in the Response type used for pagination makes sense, but I wonder if those changes could be isolated to the pagination functionality to not affect the response types for other request types (since IIUC all other API response types should be 'static.)

I messed around with this code for a bit - some other potential ideas:

  • It would be cool to be able to completely remove the lifetime requirements for P. As a (slightly ugly) idea of a potential alternative - could immediately serialize the params into something like serde_json::Value then set the cursor into that value whenever needs to be updated.

  • Another alternative to avoid the lifetimes could be to do something like store the cursor and parameters separately, so that the parameters never need to be mutated (so that when starting_after is modified, doesn't modify the passed parameters). If parameters aren't mutated, could do something like store the parameters in an Arc to avoid lifetimes. EDIT: don't think that helps

@arlyon
Copy link
Owner Author
arlyon commented Oct 31, 2022

I agree that the lifetimes definitely complicate things significantly. The idea of serializing the params immediately to a JsValue is one I hadn't considered and would simplify the types... I was trying to avoid having to special-case the codegen as much as possible so Cow (or String for that matter) was ruled out early on.

I'll have a think about this a little more, TY!

@arlyon arlyon marked this pull request as draft November 17, 2022 11:19
@arlyon arlyon force-pushed the fix/pagination-lifetimes branch from eb8d09c to 5a7a8a1 Compare January 17, 2023 13:39
@mzeitlin11 mzeitlin11 mentioned this pull request Aug 5, 2023
@mzeitlin11 mzeitlin11 mentioned this pull request Nov 26, 2023
@arlyon
Copy link
Owner Author
arlyon commented Jan 4, 2024

Closing this since it is stalled

@arlyon arlyon closed this Jan 4, 2024
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.

Expand params with anonymous lifetime is incompatible with 'static lifetime requirement of paginator
2 participants
0