aws_sdk_elastictranscoder/operation/list_pipelines/
paginator.rs

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