aws_sdk_dynamodb/operation/scan/
paginator.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2/// Paginator for [`Scan`](crate::operation::scan::Scan)
3                pub struct ScanPaginator {
4                    handle: std::sync::Arc<crate::client::Handle>,
5                    builder: crate::operation::scan::builders::ScanInputBuilder,
6                    stop_on_duplicate_token: bool,
7                }
8
9                impl ScanPaginator {
10                    /// Create a new paginator-wrapper
11                    pub(crate) fn new(handle: std::sync::Arc<crate::client::Handle>, builder: crate::operation::scan::builders::ScanInputBuilder) -> 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 `limit`_
22                    pub fn page_size(mut self, limit: i32) -> Self {
23                        self.builder.limit = ::std::option::Option::Some(limit);
24                        self
25                    }
26
27                    /// Create a flattened paginator
28                    ///
29                    /// This paginator automatically flattens results using `items`. Queries to the underlying service
30                    /// are dispatched lazily.
31                    pub fn items(self) -> crate::operation::scan::paginator::ScanPaginatorItems {
32                        crate::operation::scan::paginator::ScanPaginatorItems(self)
33                    }
34
35                    /// 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.
42                    pub fn stop_on_duplicate_token(mut self, stop_on_duplicate_token: bool) -> Self {
43                        self.stop_on_duplicate_token = stop_on_duplicate_token;
44                        self
45                    }
46
47                    /// 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).
51                    pub fn send(self) -> ::aws_smithy_async::future::pagination_stream::PaginationStream<::std::result::Result<crate::operation::scan::ScanOutput, ::aws_smithy_runtime_api::client::result::SdkError<crate::operation::scan::ScanError, ::aws_smithy_runtime_api::client::orchestrator::HttpResponse>>> {
52                        // Move individual fields out of self for the borrow checker
53                        let builder = self.builder;
54                        let handle = self.handle;
55                        let runtime_plugins = crate::operation::scan::Scan::operation_runtime_plugins(
56                                handle.runtime_plugins.clone(),
57                                &handle.conf,
58                                ::std::option::Option::None,
59                            ).with_operation_plugin(crate::sdk_feature_tracker::paginator::PaginatorFeatureTrackerRuntimePlugin::new());
60                        ::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 {
61                            // Build the input for the first time. If required fields are missing, this is where we'll produce an early error.
62                            let mut input = match builder.build().map_err(::aws_smithy_runtime_api::client::result::SdkError::construction_failure) {
63                                ::std::result::Result::Ok(input) => input,
64                                ::std::result::Result::Err(e) => { let _ = tx.send(::std::result::Result::Err(e)).await; return; }
65                            };
66                            loop {
67                                let resp = crate::operation::scan::Scan::orchestrate(&runtime_plugins, input.clone()).await;
68                                // If the input member is None or it was an error
69                                let done = match resp {
70                                    ::std::result::Result::Ok(ref resp) => {
71                                        let new_token = crate::lens::reflens_scan_output_output_last_evaluated_key(resp);
72                                        // Pagination is exhausted when the next token is an empty string
73                    let is_empty = new_token.map(|token| token.is_empty()).unwrap_or(true);
74                                        if !is_empty && new_token == input.exclusive_start_key.as_ref() && self.stop_on_duplicate_token {
75                                            true
76                                        } else {
77                                            input.exclusive_start_key = new_token.cloned();
78                                            is_empty
79                                        }
80                                    },
81                                    ::std::result::Result::Err(_) => true,
82                                };
83                                if tx.send(resp).await.is_err() {
84                                    // receiving end was dropped
85                                    return
86                                }
87                                if done {
88                                    return
89                                }
90                            }
91                        })))
92                    }
93                }
94
95/// Flattened paginator for `ScanPaginator`
96                    ///
97                    /// This is created with [`.items()`](ScanPaginator::items)
98                    pub struct ScanPaginatorItems(ScanPaginator);
99
100                    impl ScanPaginatorItems {
101                        /// Create the pagination stream
102                        ///
103                        /// _Note_: No requests will be dispatched until the stream is used
104                        /// (e.g. with the [`.next().await`](aws_smithy_async::future::pagination_stream::PaginationStream::next) method).
105                        ///
106                        /// To read the entirety of the paginator, use [`.collect::<Result<Vec<_>, _>()`](aws_smithy_async::future::pagination_stream::PaginationStream::collect).
107                        pub fn send(self) -> ::aws_smithy_async::future::pagination_stream::PaginationStream<::std::result::Result<::std::collections::HashMap::<::std::string::String, crate::types::AttributeValue>, ::aws_smithy_runtime_api::client::result::SdkError<crate::operation::scan::ScanError, ::aws_smithy_runtime_api::client::orchestrator::HttpResponse>>> {
108                            ::aws_smithy_async::future::pagination_stream::TryFlatMap::new(self.0.send()).flat_map(|page| crate::lens::lens_scan_output_output_items(page).unwrap_or_default().into_iter())
109                        }
110                    }
111