-
Notifications
You must be signed in to change notification settings - Fork 263
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
Pager rename and refactor #1836
Pager rename and refactor #1836
Conversation
Note: should see if this would close #1668 |
So, I believe #1668 is tied to #1796. Requiring that |
Cool. That's what most other languages use anyway, I believe. I know Go and JS do off hand. The "pageable" was certainly inspired by my time on the Azure SDK for .NET team.
Could we use an opaque type if public instead? It's open to change if needed - why the REST API board doesn't allow top-level JSON array responses - and more obvious what the fields are.
Our paging is already pretty HTTP-specific across most - if not all - languages, so I think this is fine. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall it looks great and the thoughts and design here are welcome! As noted, I really just have one outstanding question. We could discuss over Teams if it'd be easier or lengthy, or whatever.
Actually, I remembered this morning they use |
I think Poller might be something else. The Rust guidelines refer to |
You're right. I'm getting my wires cross. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a nit about naming, but otherwise LG(reat)TM!
Just need a code review from some Cosmos owners to merge now, since part of this PR updates the Cosmos client to use the refactored Pager (ping @FabianMeiswinkel @Pilchie @kirankumarkolli @kundadebdatta @tvaron3 , let me know if you have any questions! Happy to go over anything) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked at it before, and it looked fine to me, I just didn't want to sign-off before the broader discussion happened.
[heart] Rick Winter reacted to your message:
…________________________________
From: Ashley Stanton-Nurse ***@***.***>
Sent: Thursday, October 10, 2024 4:36:40 PM
To: Azure/azure-sdk-for-rust ***@***.***>
Cc: Rick Winter ***@***.***>; Review requested ***@***.***>
Subject: Re: [Azure/azure-sdk-for-rust] Pager rename and refactor (PR #1836)
Merged #1836<#1836> into feature/track2.
—
Reply to this email directly, view it on GitHub<#1836 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ABBZUAIRSEYEP77WJZKGW23Z22UJRAVCNFSM6AAAAABPQP3MVOVHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJUGU4TINBRGEYDANA>.
You are receiving this because your review was requested.Message ID: ***@***.***>
|
In working on pageable APIs, I found that we needed to return
Response<T>
values instead of justT
values. Rather than explode the generic type (Result<Pager<Response<T>>>
) it felt reasonable to havePager<T>
yield a stream ofResult<Response<T>>
itself. In addition,Pager<T>
depends onT
implementing a trait,Continuable
, to extract the continuation value. If we want to returnResponse<T>
(so that users can read response headers for each page), that gets very difficult and likely requires newtypes since bothResponse<T>
andContinuable
would be foreign types to service client crates and you can't implement a foreign trait on a foreign type.So, here are a few refactors to
Pageable
that I think will make it easier to use:Pager
, to align with the guidelinesResult<(Response<T>, Option<C>)>
(whereC
is anySend
able owned value). The expectation here is that the callback will returnOk((response, Some(continuation)))
to indicate a continuation andOk((response, None))
to indicate the end of the pagination. This avoids the need for theContinuable
trait entirely.Pager
yieldsResult<Response<T>>
values. This is really just shorthand. If we don't want to limit ourselves to HTTP here,Pager<T>
could becomePager<Response<T>>
without any issues, except that writing the type gets more verbose.There's a full example in the doc comments to see how you would call this. Also
azure_data_cosmos::clients::ContainerClient::query_items
has been rewritten to use it.I tried to see if we could get rid of the boxing by turning
Pager
into a trait and returning a gnarly (but largely inferred) generic type. That didn't work out, but we had boxing here before anyway and are network bound so I'm not too worried about it.In addition, I was able to remove the
declare!
macro by using conditional compilation to include/exclude theSend
bound. It makes for a slightly gnarly function definition (where clauses and individual trait bounds cannot be conditionally compiled, but<T: Bound>
syntax can). I also removed the inner module trick since it doesn't seem like I'm getting the dead-code error onproject_ref
(which makes sense since it's private to the struct, so I'm not sure why it was happening at all)