Skip to content

Commit

Permalink
Fix examples that used S3 fields that are now nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoh committed Nov 16, 2023
1 parent 295fc52 commit 8e8989e
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 10 deletions.
6 changes: 5 additions & 1 deletion rust_dev_preview/examples/s3/src/bin/s3-multipart-upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,11 @@ async fn run_example() -> Result<(), Error> {
// snippet-end:[rust.example_code.s3.complete_multipart_upload]

let data: GetObjectOutput = s3_service::download_object(&client, &bucket_name, &key).await?;
let data_length: u64 = data.content_length().try_into().unwrap();
let data_length: u64 = data
.content_length()
.unwrap_or_default()
.try_into()
.unwrap();
if file.metadata().unwrap().len() == data_length {
println!("Data lengths match.");
} else {
Expand Down
2 changes: 1 addition & 1 deletion rust_dev_preview/examples/s3/src/s3-service-lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub async fn delete_objects(client: &Client, bucket_name: &str) -> Result<Vec<St

eprintln!("{objects:?}");

match objects.key_count {
match objects.key_count.unwrap_or_default() {
0 => Ok(return_keys),
_ => Err(Error::unhandled(
"There were still objects left in the bucket.",
Expand Down
4 changes: 2 additions & 2 deletions rust_dev_preview/examples/testing/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl ListObjects {
Ok(ListObjectsResult {
objects: response.contents().to_vec(),
next_continuation_token: response.next_continuation_token.clone(),
has_more: response.is_truncated(),
has_more: response.is_truncated() == Some(true),
})
}
// snippet-end:[testing.rust.enums-real-list-objects]
Expand Down Expand Up @@ -122,7 +122,7 @@ async fn determine_prefix_file_size(

// Add up the file sizes we got back
for object in result.objects {
total_size_bytes += object.size() as usize;
total_size_bytes += object.size().unwrap_or(0) as usize;
}

// Handle pagination, and break the loop if there are no more pages
Expand Down
4 changes: 2 additions & 2 deletions rust_dev_preview/examples/testing/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ async fn determine_prefix_file_size(
// Add up the file sizes we got back
let contents = response.contents();
for object in contents {
total_size_bytes += object.size() as usize;
total_size_bytes += object.size().unwrap_or(0) as usize;
}

// Handle pagination, and break the loop if there are no more pages
next_token = response.next_continuation_token.clone();
if !response.is_truncated() {
if response.is_truncated() != Some(true) {
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion rust_dev_preview/examples/testing/src/replay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub async fn determine_prefix_file_size(

// Add up the file sizes we got back
for object in result.contents() {
total_size_bytes += object.size() as usize;
total_size_bytes += object.size().unwrap_or(0) as usize;
}

// Handle pagination, and break the loop if there are no more pages
Expand Down
4 changes: 2 additions & 2 deletions rust_dev_preview/examples/testing/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl ListObjects for S3ListObjects {
Ok(ListObjectsResult {
objects: response.contents().to_vec(),
next_continuation_token: response.next_continuation_token.clone(),
has_more: response.is_truncated(),
has_more: response.is_truncated() == Some(true),
})
}
}
Expand Down Expand Up @@ -119,7 +119,7 @@ pub async fn determine_prefix_file_size(

// Add up the file sizes we got back
for object in result.objects {
total_size_bytes += object.size() as usize;
total_size_bytes += object.size().unwrap_or(0) as usize;
}

// Handle pagination, and break the loop if there are no more pages
Expand Down
2 changes: 1 addition & 1 deletion rust_dev_preview/examples/testing/src/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub async fn determine_prefix_file_size(

// Add up the file sizes we got back
for object in result.contents() {
total_size_bytes += object.size() as usize;
total_size_bytes += object.size().unwrap_or(0) as usize;
}

// Handle pagination, and break the loop if there are no more pages
Expand Down

0 comments on commit 8e8989e

Please sign in to comment.