google_cloud_storage/storage/stub.rs
1// Copyright 2025 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use crate::Result;
16use crate::model::{Object, ReadObjectRequest};
17use crate::model_ext::WriteObjectRequest;
18use crate::read_object::ReadObjectResponse;
19use crate::storage::request_options::RequestOptions;
20use crate::streaming_source::{Seek, StreamingSource};
21use gaxi::unimplemented::UNIMPLEMENTED;
22
23/// Defines the trait used to implement [crate::client::Storage].
24///
25/// Application developers may need to implement this trait to mock
26/// `client::Storage`. In other use-cases, application developers only
27/// use `client::Storage` and need not be concerned with this trait or
28/// its implementations.
29///
30/// Services gain new RPCs routinely. Consequently, this trait gains new methods
31/// too. To avoid breaking applications the trait provides a default
32/// implementation of each method. Most of these implementations just return an
33/// error.
34pub trait Storage: std::fmt::Debug + Send + Sync {
35 /// Implements [crate::client::Storage::read_object].
36 fn read_object(
37 &self,
38 _req: ReadObjectRequest,
39 _options: RequestOptions,
40 ) -> impl std::future::Future<Output = Result<ReadObjectResponse>> + Send {
41 unimplemented_stub::<ReadObjectResponse>()
42 }
43
44 /// Implements [crate::client::Storage::write_object].
45 #[allow(dead_code)] // TODO(#2041) - implement writes
46 fn write_object_buffered<P>(
47 &self,
48 _payload: P,
49 _req: WriteObjectRequest,
50 _options: RequestOptions,
51 ) -> impl std::future::Future<Output = Result<Object>> + Send
52 where
53 P: StreamingSource + Send + Sync + 'static,
54 {
55 unimplemented_stub::<Object>()
56 }
57
58 /// Implements [crate::client::Storage::write_object].
59 #[allow(dead_code)] // TODO(#2041) - implement writes
60 fn write_object_unbuffered<P>(
61 &self,
62 _payload: P,
63 _req: WriteObjectRequest,
64 _options: RequestOptions,
65 ) -> impl std::future::Future<Output = Result<Object>> + Send
66 where
67 P: StreamingSource + Seek + Send + Sync + 'static,
68 {
69 unimplemented_stub::<Object>()
70 }
71}
72
73async fn unimplemented_stub<T>() -> gax::Result<T> {
74 unimplemented!("{UNIMPLEMENTED}");
75}