I would like to write a function that uses the aws s3 api to list the contents of a bucket (a list of ListBucketResponse
) and return just the contents
field from the first element for (immutable) use elsewhere in the application. Currently I get the error:
error[E0507]: cannot move out of a shared reference
--> src\main.rs:99:5
|
99 | list_result.first().unwrap().contents
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ move occurs because value has type `Vec<Object>`, which does not implement the `Copy` trait
from the following code:
async fn get_bucket_contents
(s3_client: Bucket) -> Vec<Object>
{
let list_result = s3_client
.list("".to_string(), None)
.await
.expect("failed to list s3 contents");
list_result.first().unwrap().contents
}
Why is the list_result
reference shared? I thought it would be owned entirely by this function and could transfer ownership of a child property when the function terminates.
thank you all in advance for your help!