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};
21#[cfg(google_cloud_unstable_storage_bidi)]
22use crate::{
23    model_ext::{OpenObjectRequest, ReadRange},
24    object_descriptor::ObjectDescriptor as Descriptor,
25};
26use gaxi::unimplemented::UNIMPLEMENTED;
27
28/// Defines the trait used to implement [crate::client::Storage].
29///
30/// Application developers may need to implement this trait to mock
31/// `client::Storage`. In other use-cases, application developers only
32/// use `client::Storage` and need not be concerned with this trait or
33/// its implementations.
34///
35/// Services gain new RPCs routinely. Consequently, this trait gains new methods
36/// too. To avoid breaking applications the trait provides a default
37/// implementation of each method. Most of these implementations just return an
38/// error.
39pub trait Storage: std::fmt::Debug + Send + Sync {
40    /// Implements [crate::client::Storage::read_object].
41    fn read_object(
42        &self,
43        _req: ReadObjectRequest,
44        _options: RequestOptions,
45    ) -> impl std::future::Future<Output = Result<ReadObjectResponse>> + Send {
46        unimplemented_stub::<ReadObjectResponse>()
47    }
48
49    /// Implements [crate::client::Storage::write_object].
50    fn write_object_buffered<P>(
51        &self,
52        _payload: P,
53        _req: WriteObjectRequest,
54        _options: RequestOptions,
55    ) -> impl std::future::Future<Output = Result<Object>> + Send
56    where
57        P: StreamingSource + Send + Sync + 'static,
58    {
59        unimplemented_stub::<Object>()
60    }
61
62    /// Implements [crate::client::Storage::write_object].
63    fn write_object_unbuffered<P>(
64        &self,
65        _payload: P,
66        _req: WriteObjectRequest,
67        _options: RequestOptions,
68    ) -> impl std::future::Future<Output = Result<Object>> + Send
69    where
70        P: StreamingSource + Seek + Send + Sync + 'static,
71    {
72        unimplemented_stub::<Object>()
73    }
74
75    #[cfg(google_cloud_unstable_storage_bidi)]
76    /// Implements [crate::client::Storage::open_object].
77    fn open_object(
78        &self,
79        _request: OpenObjectRequest,
80        _options: RequestOptions,
81    ) -> impl std::future::Future<Output = Result<Descriptor>> + Send {
82        unimplemented_stub::<Descriptor>()
83    }
84}
85
86#[cfg(google_cloud_unstable_storage_bidi)]
87/// Defines the trait used to implement [crate::object_descriptor::ObjectDescriptor].
88///
89/// Application developers may need to implement this trait to mock
90/// `ObjectDescriptor`. In other use-cases, application developers
91/// should use `ObjectDescriptor` directly, and need not be concerned
92/// with this trait or its implementations.
93pub trait ObjectDescriptor: std::fmt::Debug + Send + Sync {
94    /// The implementation for [ObjectDescriptor::object][Descriptor::object].
95    fn object(&self) -> &Object;
96
97    /// The implementation for [ObjectDescriptor::read_range][Descriptor::read_range].
98    fn read_range(
99        &self,
100        range: ReadRange,
101    ) -> impl Future<Output = ReadObjectResponse> + Send + Sync;
102}
103
104async fn unimplemented_stub<T>() -> gax::Result<T> {
105    unimplemented!("{UNIMPLEMENTED}");
106}