Replies: 1 comment 1 reply
-
Perhaps a dumb question as I don't know Rust, but in the examples above, there is always an outer loop iterating over pages. Will there be a way to simply iterate (lazily) over the results (vs pages) without a double loop? I'm just accustomed to Boto3 resource objects abstracting away pagination entirely for me:
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Summary
Smithy models paginated responses. Customers of Smithy generated code & the Rust SDK will have an improved user experience if code is generated to support this.
In this RFC, we propose modeling paginated data as a
Stream
of output shapes.paginate()
method will be added to the high level builder<OperationName>Paginator
struct will be generated into thepaginator
module.The
Stream
trait enables customers to use a number of abstractions including simple looping, andcollect()
ing all data in a single call.A paginator will resend the original input, but with the field marked
inputToken
to the value ofoutputToken
in the previous output.Usage example:
Paginators are lazy and only retrieve pages when polled by a client.
Details
A draft implementation (not code generated) is here: #344.
Paginators will be generated into the
paginator
module of service crates.paginators
will be an optional but enabled-by-default Cargo feature for AWS services. Apaginator
struct captures 4 pieces of data:In addition to the basic usage example above, when
pageSize
is modeled, customers can specify the page size during pagination:Paginators define a single public method
send()
. This method returnsimpl Stream<Item=Result<OperationOutput, OperationError>
. The current plan-of-record is to useAsyncStream
internally.AsyncStream
essentially implements a rendezvous channel to enable yielding items 1-by-1 in a demand driven way:On Box::pin: The stream returned by
AsyncStream
does not implementUnpin
. Unfortunately, this makes iteration require an invocation ofpin_mut!
and generates several hundred lines of compiler errors. Box::pin seems a worthwhile trade off to improve the user experience.On the
+ Unpin
bound: Because auto-traits leak acrossimpl Trait
boundaries,+ Unpin
prevents accidental regressions in the generated code which would break users.Updates to ergonomic clients
The
builders
generated by ergonomic clients will gain the following method, iff they represent an operation targeted by thepaginated
trait:Wrinkles
In order to be usable from outside the ergonomic clients, paginators need to be able accept
client
andconf
directly. Currently,Handle
is defined within theclient
module which is feature gated. This would need to be extracted so that it could be used within the paginators. Some considerations also need to be made about ownership. We don't necessarily want to force low-level customers toArc
their clients but this can be an area of ongoing research.Beta Was this translation helpful? Give feedback.
All reactions