1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2/// Paginator for [`ListObjectsV2`](crate::operation::list_objects_v2::ListObjectsV2)
3pub struct ListObjectsV2Paginator {
4 handle: std::sync::Arc<crate::client::Handle>,
5 builder: crate::operation::list_objects_v2::builders::ListObjectsV2InputBuilder,
6 stop_on_duplicate_token: bool,
7}
89impl ListObjectsV2Paginator {
10/// Create a new paginator-wrapper
11pub(crate) fn new(
12 handle: std::sync::Arc<crate::client::Handle>,
13 builder: crate::operation::list_objects_v2::builders::ListObjectsV2InputBuilder,
14 ) -> Self {
15Self {
16 handle,
17 builder,
18 stop_on_duplicate_token: true,
19 }
20 }
2122/// Set the page size
23 ///
24 /// _Note: this method will override any previously set value for `max_keys`_
25pub fn page_size(mut self, limit: i32) -> Self {
26self.builder.max_keys = ::std::option::Option::Some(limit);
27self
28}
2930/// 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.
37pub fn stop_on_duplicate_token(mut self, stop_on_duplicate_token: bool) -> Self {
38self.stop_on_duplicate_token = stop_on_duplicate_token;
39self
40}
4142/// 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).
46pub fn send(
47self,
48 ) -> ::aws_smithy_async::future::pagination_stream::PaginationStream<
49 ::std::result::Result<
50crate::operation::list_objects_v2::ListObjectsV2Output,
51 ::aws_smithy_runtime_api::client::result::SdkError<
52crate::operation::list_objects_v2::ListObjectsV2Error,
53 ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
54 >,
55 >,
56 > {
57// Move individual fields out of self for the borrow checker
58let builder = self.builder;
59let handle = self.handle;
60let runtime_plugins = crate::operation::list_objects_v2::ListObjectsV2::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(
67move |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.
70let 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) => {
76let _ = tx.send(::std::result::Result::Err(e)).await;
77return;
78 }
79 };
80loop {
81let resp = crate::operation::list_objects_v2::ListObjectsV2::orchestrate(&runtime_plugins, input.clone()).await;
82// If the input member is None or it was an error
83let done = match resp {
84 ::std::result::Result::Ok(ref resp) => {
85let new_token = crate::lens::reflens_list_objects_v2_output_output_next_continuation_token(resp);
86// Pagination is exhausted when the next token is an empty string
87let is_empty = new_token.map(|token| token.is_empty()).unwrap_or(true);
88if !is_empty && new_token == input.continuation_token.as_ref() && self.stop_on_duplicate_token {
89true
90} else {
91 input.continuation_token = new_token.cloned();
92 is_empty
93 }
94 }
95 ::std::result::Result::Err(_) => true,
96 };
97if tx.send(resp).await.is_err() {
98// receiving end was dropped
99return;
100 }
101if done {
102return;
103 }
104 }
105 })
106 },
107 ))
108 }
109}