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