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 fn write_object_buffered<P>(
46 &self,
47 _payload: P,
48 _req: WriteObjectRequest,
49 _options: RequestOptions,
50 ) -> impl std::future::Future<Output = Result<Object>> + Send
51 where
52 P: StreamingSource + Send + Sync + 'static,
53 {
54 unimplemented_stub::<Object>()
55 }
56
57 /// Implements [crate::client::Storage::write_object].
58 fn write_object_unbuffered<P>(
59 &self,
60 _payload: P,
61 _req: WriteObjectRequest,
62 _options: RequestOptions,
63 ) -> impl std::future::Future<Output = Result<Object>> + Send
64 where
65 P: StreamingSource + Seek + Send + Sync + 'static,
66 {
67 unimplemented_stub::<Object>()
68 }
69}
70
71async fn unimplemented_stub<T>() -> gax::Result<T> {
72 unimplemented!("{UNIMPLEMENTED}");
73}