Because multiple requests might be required to complete a rewrite of a large object, you need to call the rewrite in a loop. The documentation could be improved to make this more obvious. Something like this:
use google_cloud_storage::client::Client;
use google_cloud_storage::http::objects::rewrite::RewriteObjectRequest;
#[tokio::main]
async fn main() {
let mut done = false;
let mut rewrite_token = None;
let client = Client::default().await.unwrap();
while !done {
let result = client.rewrite_object(&RewriteObjectRequest{
source_bucket: "bucket1".to_string(),
source_object: "object".to_string(),
destination_bucket: "bucket2".to_string(),
destination_object: "object1".to_string(),
rewrite_token: rewrite_token.clone(),
..Default::default()
}, None).await;
done = result.done;
rewrite_token = result.rewrite_token;
}
}
Because multiple requests might be required to complete a rewrite of a large object, you need to call the rewrite in a loop. The documentation could be improved to make this more obvious. Something like this: