From b76a64fcb63e72bef19897dd24ff24aa501441ee Mon Sep 17 00:00:00 2001 From: Sharon Lynn Date: Fri, 21 Aug 2026 02:40:00 +0000 Subject: [PATCH] docs(storage): add code sample for send_and_append --- src/storage/examples/src/lib.rs | 8 +++++ src/storage/examples/src/objects.rs | 2 ++ .../open_appendable_object_send_and_append.rs | 30 +++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 src/storage/examples/src/objects/open_appendable_object_send_and_append.rs diff --git a/src/storage/examples/src/lib.rs b/src/storage/examples/src/lib.rs index 3cf08b8bef..bcc603f756 100644 --- a/src/storage/examples/src/lib.rs +++ b/src/storage/examples/src/lib.rs @@ -608,6 +608,14 @@ async fn run_object_appendable_examples( .send() .await?; + tracing::info!("running open_appendable_object_send_and_append example"); + objects::open_appendable_object_send_and_append::sample( + client, + &rapid_bucket_id, + "appendable-send-and-append", + ) + .await?; + tracing::info!("running open_appendable_object_write example"); objects::open_appendable_object_write::sample(client, &rapid_bucket_id, "appendable-write") .await?; diff --git a/src/storage/examples/src/objects.rs b/src/storage/examples/src/objects.rs index 3efbf0ace6..04ab835169 100644 --- a/src/storage/examples/src/objects.rs +++ b/src/storage/examples/src/objects.rs @@ -48,6 +48,8 @@ pub mod open_appendable_object_pause_resume; #[cfg(google_cloud_unstable_storage_bidi)] pub mod open_appendable_object_read_tail; #[cfg(google_cloud_unstable_storage_bidi)] +pub mod open_appendable_object_send_and_append; +#[cfg(google_cloud_unstable_storage_bidi)] pub mod open_appendable_object_write; pub mod open_multiple_objects_ranged_read; pub mod open_object_multiple_ranged_read; diff --git a/src/storage/examples/src/objects/open_appendable_object_send_and_append.rs b/src/storage/examples/src/objects/open_appendable_object_send_and_append.rs new file mode 100644 index 0000000000..10466d3b8a --- /dev/null +++ b/src/storage/examples/src/objects/open_appendable_object_send_and_append.rs @@ -0,0 +1,30 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// [START storage_open_appendable_object_send_and_append] +use bytes::Bytes; +use google_cloud_storage::client::Storage; + +pub async fn sample(client: &Storage, bucket: &str, object: &str) -> Result<(), anyhow::Error> { + let writer = client + .open_appendable_object(format!("projects/_/buckets/{bucket}"), object) + .send_and_append(Bytes::from("Hello World!")) + .await?; + + let metadata = writer.finalize().await?; + + println!("Created and appended data to {object} in bucket {bucket}: {metadata:?}"); + Ok(()) +} +// [END storage_open_appendable_object_send_and_append]