aws_sdk_ec2/operation/describe_local_gateway_virtual_interfaces/
paginator.rs

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