1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2/// Paginator for [`ListAccounts`](crate::operation::list_accounts::ListAccounts)
3pub struct ListAccountsPaginator {
4 handle: std::sync::Arc<crate::client::Handle>,
5 builder: crate::operation::list_accounts::builders::ListAccountsInputBuilder,
6 stop_on_duplicate_token: bool,
7}
89impl ListAccountsPaginator {
10/// Create a new paginator-wrapper
11pub(crate) fn new(
12 handle: std::sync::Arc<crate::client::Handle>,
13 builder: crate::operation::list_accounts::builders::ListAccountsInputBuilder,
14 ) -> Self {
15Self {
16 handle,
17 builder,
18 stop_on_duplicate_token: true,
19 }
20 }
2122/// Set the page size
23 ///
24 /// _Note: this method will override any previously set value for `max_results`_
25pub fn page_size(mut self, limit: i32) -> Self {
26self.builder.max_results = ::std::option::Option::Some(limit);
27self
28}
2930/// Create a flattened paginator
31 ///
32 /// This paginator automatically flattens results using `account_list`. Queries to the underlying service
33 /// are dispatched lazily.
34pub fn items(self) -> crate::operation::list_accounts::paginator::ListAccountsPaginatorItems {
35crate::operation::list_accounts::paginator::ListAccountsPaginatorItems(self)
36 }
3738/// Stop paginating when the service returns the same pagination token twice in a row.
39 ///
40 /// Defaults to true.
41 ///
42 /// For certain operations, it may be useful to continue on duplicate token. For example,
43 /// if an operation is for tailing a log file in real-time, then continuing may be desired.
44 /// This option can be set to `false` to accommodate these use cases.
45pub fn stop_on_duplicate_token(mut self, stop_on_duplicate_token: bool) -> Self {
46self.stop_on_duplicate_token = stop_on_duplicate_token;
47self
48}
4950/// Create the pagination stream
51 ///
52 /// _Note:_ No requests will be dispatched until the stream is used
53 /// (e.g. with the [`.next().await`](aws_smithy_async::future::pagination_stream::PaginationStream::next) method).
54pub fn send(
55self,
56 ) -> ::aws_smithy_async::future::pagination_stream::PaginationStream<
57 ::std::result::Result<
58crate::operation::list_accounts::ListAccountsOutput,
59 ::aws_smithy_runtime_api::client::result::SdkError<
60crate::operation::list_accounts::ListAccountsError,
61 ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
62 >,
63 >,
64 > {
65// Move individual fields out of self for the borrow checker
66let builder = self.builder;
67let handle = self.handle;
68let runtime_plugins = crate::operation::list_accounts::ListAccounts::operation_runtime_plugins(
69 handle.runtime_plugins.clone(),
70&handle.conf,
71 ::std::option::Option::None,
72 )
73 .with_operation_plugin(crate::sdk_feature_tracker::paginator::PaginatorFeatureTrackerRuntimePlugin::new());
74 ::aws_smithy_async::future::pagination_stream::PaginationStream::new(::aws_smithy_async::future::pagination_stream::fn_stream::FnStream::new(
75move |tx| {
76 ::std::boxed::Box::pin(async move {
77// Build the input for the first time. If required fields are missing, this is where we'll produce an early error.
78let mut input = match builder
79 .build()
80 .map_err(::aws_smithy_runtime_api::client::result::SdkError::construction_failure)
81 {
82 ::std::result::Result::Ok(input) => input,
83 ::std::result::Result::Err(e) => {
84let _ = tx.send(::std::result::Result::Err(e)).await;
85return;
86 }
87 };
88loop {
89let resp = crate::operation::list_accounts::ListAccounts::orchestrate(&runtime_plugins, input.clone()).await;
90// If the input member is None or it was an error
91let done = match resp {
92 ::std::result::Result::Ok(ref resp) => {
93let new_token = crate::lens::reflens_list_accounts_output_output_next_token(resp);
94// Pagination is exhausted when the next token is an empty string
95let is_empty = new_token.map(|token| token.is_empty()).unwrap_or(true);
96if !is_empty && new_token == input.next_token.as_ref() && self.stop_on_duplicate_token {
97true
98} else {
99 input.next_token = new_token.cloned();
100 is_empty
101 }
102 }
103 ::std::result::Result::Err(_) => true,
104 };
105if tx.send(resp).await.is_err() {
106// receiving end was dropped
107return;
108 }
109if done {
110return;
111 }
112 }
113 })
114 },
115 ))
116 }
117}
118119/// Flattened paginator for `ListAccountsPaginator`
120///
121/// This is created with [`.items()`](ListAccountsPaginator::items)
122pub struct ListAccountsPaginatorItems(ListAccountsPaginator);
123124impl ListAccountsPaginatorItems {
125/// Create the pagination stream
126 ///
127 /// _Note_: No requests will be dispatched until the stream is used
128 /// (e.g. with the [`.next().await`](aws_smithy_async::future::pagination_stream::PaginationStream::next) method).
129 ///
130 /// To read the entirety of the paginator, use [`.collect::<Result<Vec<_>, _>()`](aws_smithy_async::future::pagination_stream::PaginationStream::collect).
131pub fn send(
132self,
133 ) -> ::aws_smithy_async::future::pagination_stream::PaginationStream<
134 ::std::result::Result<
135crate::types::AccountInfo,
136 ::aws_smithy_runtime_api::client::result::SdkError<
137crate::operation::list_accounts::ListAccountsError,
138 ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
139 >,
140 >,
141 > {
142 ::aws_smithy_async::future::pagination_stream::TryFlatMap::new(self.0.send()).flat_map(|page| {
143crate::lens::lens_list_accounts_output_output_account_list(page)
144 .unwrap_or_default()
145 .into_iter()
146 })
147 }
148}