aws_sdk_databasemigration/operation/describe_applicable_individual_assessments/
paginator.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2/// Paginator for [`DescribeApplicableIndividualAssessments`](crate::operation::describe_applicable_individual_assessments::DescribeApplicableIndividualAssessments)
3pub struct DescribeApplicableIndividualAssessmentsPaginator {
4    handle: std::sync::Arc<crate::client::Handle>,
5    builder: crate::operation::describe_applicable_individual_assessments::builders::DescribeApplicableIndividualAssessmentsInputBuilder,
6    stop_on_duplicate_token: bool,
7}
8
9impl DescribeApplicableIndividualAssessmentsPaginator {
10    /// Create a new paginator-wrapper
11    pub(crate) fn new(
12        handle: std::sync::Arc<crate::client::Handle>,
13        builder: crate::operation::describe_applicable_individual_assessments::builders::DescribeApplicableIndividualAssessmentsInputBuilder,
14    ) -> Self {
15        Self {
16            handle,
17            builder,
18            stop_on_duplicate_token: true,
19        }
20    }
21
22    /// Set the page size
23    ///
24    /// _Note: this method will override any previously set value for `max_records`_
25    pub fn page_size(mut self, limit: i32) -> Self {
26        self.builder.max_records = ::std::option::Option::Some(limit);
27        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::describe_applicable_individual_assessments::DescribeApplicableIndividualAssessmentsOutput,
51            ::aws_smithy_runtime_api::client::result::SdkError<
52                crate::operation::describe_applicable_individual_assessments::DescribeApplicableIndividualAssessmentsError,
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 =
61            crate::operation::describe_applicable_individual_assessments::DescribeApplicableIndividualAssessments::operation_runtime_plugins(
62                handle.runtime_plugins.clone(),
63                &handle.conf,
64                ::std::option::Option::None,
65            )
66            .with_operation_plugin(crate::sdk_feature_tracker::paginator::PaginatorFeatureTrackerRuntimePlugin::new());
67        ::aws_smithy_async::future::pagination_stream::PaginationStream::new(::aws_smithy_async::future::pagination_stream::fn_stream::FnStream::new(
68            move |tx| {
69                ::std::boxed::Box::pin(async move {
70                    // Build the input for the first time. If required fields are missing, this is where we'll produce an early error.
71                    let mut input = match builder
72                        .build()
73                        .map_err(::aws_smithy_runtime_api::client::result::SdkError::construction_failure)
74                    {
75                        ::std::result::Result::Ok(input) => input,
76                        ::std::result::Result::Err(e) => {
77                            let _ = tx.send(::std::result::Result::Err(e)).await;
78                            return;
79                        }
80                    };
81                    loop {
82                        let resp =
83                            crate::operation::describe_applicable_individual_assessments::DescribeApplicableIndividualAssessments::orchestrate(
84                                &runtime_plugins,
85                                input.clone(),
86                            )
87                            .await;
88                        // If the input member is None or it was an error
89                        let done = match resp {
90                            ::std::result::Result::Ok(ref resp) => {
91                                let new_token = crate::lens::reflens_describe_applicable_individual_assessments_output_output_marker(resp);
92                                // Pagination is exhausted when the next token is an empty string
93                                let is_empty = new_token.map(|token| token.is_empty()).unwrap_or(true);
94                                if !is_empty && new_token == input.marker.as_ref() && self.stop_on_duplicate_token {
95                                    true
96                                } else {
97                                    input.marker = new_token.cloned();
98                                    is_empty
99                                }
100                            }
101                            ::std::result::Result::Err(_) => true,
102                        };
103                        if tx.send(resp).await.is_err() {
104                            // receiving end was dropped
105                            return;
106                        }
107                        if done {
108                            return;
109                        }
110                    }
111                })
112            },
113        ))
114    }
115}