aws_sdk_dynamodb/operation/list_imports/paginator.rs
1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2/// Paginator for [`ListImports`](crate::operation::list_imports::ListImports)
3 pub struct ListImportsPaginator {
4 handle: std::sync::Arc<crate::client::Handle>,
5 builder: crate::operation::list_imports::builders::ListImportsInputBuilder,
6 stop_on_duplicate_token: bool,
7 }
8
9 impl ListImportsPaginator {
10 /// Create a new paginator-wrapper
11 pub(crate) fn new(handle: std::sync::Arc<crate::client::Handle>, builder: crate::operation::list_imports::builders::ListImportsInputBuilder) -> Self {
12 Self {
13 handle,
14 builder,
15 stop_on_duplicate_token: true,
16 }
17 }
18
19 /// Set the page size
20 ///
21 /// _Note: this method will override any previously set value for `page_size`_
22 pub fn page_size(mut self, limit: i32) -> Self {
23 self.builder.page_size = ::std::option::Option::Some(limit);
24 self
25 }
26
27
28
29 /// Stop paginating when the service returns the same pagination token twice in a row.
30 ///
31 /// Defaults to true.
32 ///
33 /// For certain operations, it may be useful to continue on duplicate token. For example,
34 /// if an operation is for tailing a log file in real-time, then continuing may be desired.
35 /// This option can be set to `false` to accommodate these use cases.
36 pub fn stop_on_duplicate_token(mut self, stop_on_duplicate_token: bool) -> Self {
37 self.stop_on_duplicate_token = stop_on_duplicate_token;
38 self
39 }
40
41 /// Create the pagination stream
42 ///
43 /// _Note:_ No requests will be dispatched until the stream is used
44 /// (e.g. with the [`.next().await`](aws_smithy_async::future::pagination_stream::PaginationStream::next) method).
45 pub fn send(self) -> ::aws_smithy_async::future::pagination_stream::PaginationStream<::std::result::Result<crate::operation::list_imports::ListImportsOutput, ::aws_smithy_runtime_api::client::result::SdkError<crate::operation::list_imports::ListImportsError, ::aws_smithy_runtime_api::client::orchestrator::HttpResponse>>> {
46 // Move individual fields out of self for the borrow checker
47 let builder = self.builder;
48 let handle = self.handle;
49 let runtime_plugins = crate::operation::list_imports::ListImports::operation_runtime_plugins(
50 handle.runtime_plugins.clone(),
51 &handle.conf,
52 ::std::option::Option::None,
53 ).with_operation_plugin(crate::sdk_feature_tracker::paginator::PaginatorFeatureTrackerRuntimePlugin::new());
54 ::aws_smithy_async::future::pagination_stream::PaginationStream::new(::aws_smithy_async::future::pagination_stream::fn_stream::FnStream::new(move |tx| ::std::boxed::Box::pin(async move {
55 // Build the input for the first time. If required fields are missing, this is where we'll produce an early error.
56 let mut input = match builder.build().map_err(::aws_smithy_runtime_api::client::result::SdkError::construction_failure) {
57 ::std::result::Result::Ok(input) => input,
58 ::std::result::Result::Err(e) => { let _ = tx.send(::std::result::Result::Err(e)).await; return; }
59 };
60 loop {
61 let resp = crate::operation::list_imports::ListImports::orchestrate(&runtime_plugins, input.clone()).await;
62 // If the input member is None or it was an error
63 let done = match resp {
64 ::std::result::Result::Ok(ref resp) => {
65 let new_token = crate::lens::reflens_list_imports_output_output_next_token(resp);
66 // Pagination is exhausted when the next token is an empty string
67 let is_empty = new_token.map(|token| token.is_empty()).unwrap_or(true);
68 if !is_empty && new_token == input.next_token.as_ref() && self.stop_on_duplicate_token {
69 true
70 } else {
71 input.next_token = new_token.cloned();
72 is_empty
73 }
74 },
75 ::std::result::Result::Err(_) => true,
76 };
77 if tx.send(resp).await.is_err() {
78 // receiving end was dropped
79 return
80 }
81 if done {
82 return
83 }
84 }
85 })))
86 }
87 }
88