Skip to content

Commit

Permalink
Rust: Use into_paginator().items() when available. (#5603)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidSouther authored Nov 2, 2023
1 parent 696e46b commit 9465b36
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 31 deletions.
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

0 comments on commit 9465b36

Please sign in to comment.