Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust: Use into_paginator().items() when available. #5603

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,21 @@ struct Opt {
async fn show_accelerators(client: &Client) -> Result<(), Error> {
println!("Welcome to the AWS Rust SDK Global Accelerator example!");
println!();
let mut paginator = client.list_accelerators().into_paginator().send();
let accelerators = client
.list_accelerators()
.into_paginator()
.items()
.send()
.try_collect()
.await?;

while let Some(page) = paginator.try_next().await? {
for accelerator in page.accelerators().iter() {
let accelerator_arn = accelerator.name().unwrap_or_default();
let accelerator_name = accelerator.accelerator_arn().unwrap_or_default();
for accelerator in accelerators {
let accelerator_arn = accelerator.name().unwrap_or_default();
let accelerator_name = accelerator.accelerator_arn().unwrap_or_default();

println!("Accelerator Name : {}", accelerator_name);
println!("Accelerator ARN : {}", accelerator_arn);
println!();
}
println!("Accelerator Name : {}", accelerator_name);
println!("Accelerator ARN : {}", accelerator_arn);
println!();
}

Ok(())
Expand Down
39 changes: 17 additions & 22 deletions rust_dev_preview/examples/iam/src/iam-service-lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,33 +371,28 @@ pub async fn list_policies(
client: iamClient,
path_prefix: String,
) -> Result<Vec<String>, SdkError<ListPoliciesError>> {
let mut list_policies = client
let list_policies = client
.list_policies()
.path_prefix(path_prefix)
.scope(PolicyScopeType::Local)
.into_paginator()
.send();

let mut v = Vec::new();

while let Some(list_policies_output) = list_policies.next().await {
match list_policies_output {
Ok(list_policies) => {
for policy in list_policies.policies() {
let policy_name = policy
.policy_name()
.unwrap_or("Missing policy name.")
.to_string();
println!("{}", policy_name);
v.push(policy_name);
}
}

Err(err) => return Err(err),
}
}
.items()
.send()
.try_collect()
.await?;

Ok(v)
let policy_names = list_policies
.into_iter()
.map(|p| {
let name = p
.policy_name
.unwrap_or_else(|| "Missing Policy Name".to_string());
println!("{}", name);
name
})
.collect();

Ok(policy_names)
}
// snippet-end:[rust.example_code.iam.hello_lib]
// snippet-end:[rust.example_code.iam.service.list_policies]
Expand Down
Loading