Skip to main content

google_cloud_storage/
lib.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
15//! Google Cloud Client Libraries for Rust - Storage
16//!
17//! This crate contains traits, types, and functions to interact with [Google
18//! Cloud Storage]. Most applications will use the structs defined in the
19//! [client] module. More specifically:
20//!
21//! * [Storage][client::Storage]
22//! * [StorageControl][client::StorageControl]
23//! * [SignedUrlBuilder][builder::storage::SignedUrlBuilder]
24//!
25//! **NOTE:** This crate used to contain a different implementation, with a
26//! different surface. [@yoshidan](https://github.com/yoshidan) generously
27//! donated the crate name to Google. Their crate continues to live as
28//! [gcloud-storage].
29//!
30//! # Features
31//!
32//! - `default-rustls-provider`: enabled by default. Use the default rustls crypto
33//!   provider ([aws-lc-rs]) for TLS and authentication. Applications with specific
34//!   requirements for cryptography (such as exclusively using the [ring] crate)
35//!   should disable this default and call
36//!   `rustls::crypto::CryptoProvider::install_default()`.
37//! - `unstable-stream`: enable the (unstable) features to convert several types to
38//!   a `future::Stream`.
39//!
40//! [aws-lc-rs]: https://crates.io/crates/aws-lc-rs
41//! [gcloud-storage]: https://crates.io/crates/gcloud-storage
42//! [Google Cloud Storage]: https://cloud.google.com/storage
43//! [ring]: https://crates.io/crates/ring
44
45#![cfg_attr(docsrs, feature(doc_cfg))]
46
47pub use google_cloud_gax::Result;
48pub use google_cloud_gax::error::Error;
49// Define some shortcuts for imported crates.
50pub(crate) use google_cloud_gax::client_builder::ClientBuilder;
51pub(crate) use google_cloud_gax::client_builder::Result as ClientBuilderResult;
52pub(crate) use google_cloud_gax::client_builder::internal::ClientFactory;
53pub(crate) use google_cloud_gax::client_builder::internal::new_builder as new_client_builder;
54pub(crate) use google_cloud_gax::options::RequestOptions;
55pub(crate) use google_cloud_gax::options::internal::RequestBuilder;
56pub(crate) use google_cloud_gax::response::Response;
57
58#[cfg(google_cloud_unstable_storage_bidi)]
59#[cfg_attr(docsrs, doc(cfg(feature = "unstable-stream")))]
60pub mod appendable_object_writer;
61pub mod backoff_policy;
62pub mod object_descriptor;
63pub mod read_object;
64pub mod read_resume_policy;
65pub mod retry_policy;
66pub mod signed_url;
67pub use crate::storage::request_options;
68pub use crate::storage::streaming_source;
69
70/// Re-export types from the `http` crate used in this module.
71pub mod http {
72    // Note: The empty doc lines below create a paragraph break in Markdown.
73    // This prevents rustdoc from appending the inlined external documentation
74    // to our short descriptions in the module summary list.
75
76    /// HTTP method used by the [SignedUrlBuilder][crate::builder::storage::SignedUrlBuilder].
77    ///
78    ///
79    pub use http::Method;
80
81    /// Metadata attributes used by the [Client::open_object][crate::client::Storage::open_object].
82    ///
83    ///
84    pub use http::HeaderMap;
85}
86
87mod control;
88mod storage;
89
90pub mod client {
91    //! Clients to interact with Google Cloud Storage.
92    pub use crate::control::client::StorageControl;
93    pub use crate::storage::client::Storage;
94}
95pub mod builder {
96    //! Request builders.
97    pub mod storage {
98        //! Request builders for [Storage][crate::client::Storage].
99        pub use crate::storage::client::ClientBuilder;
100        pub use crate::storage::open_object::OpenObject;
101        pub use crate::storage::post_policy::{PostPolicyV4Builder, PostPolicyV4Result};
102        pub use crate::storage::read_object::ReadObject;
103        pub use crate::storage::signed_url::SignedUrlBuilder;
104        pub use crate::storage::write_object::WriteObject;
105    }
106    pub mod storage_control {
107        //! Request builders for [StorageControl][crate::client::StorageControl].
108        pub use crate::control::builder::*;
109        pub use crate::control::client::ClientBuilder;
110    }
111}
112pub mod error;
113pub use crate::control::model;
114pub mod builder_ext;
115pub mod model_ext;
116pub mod stub {
117    //! Traits to mock the clients in this library.
118    //!
119    //! Application developers may need to mock the clients in this library to test
120    //! how their application works with different (and sometimes hard to trigger)
121    //! client and service behavior. Such test can define mocks implementing the
122    //! trait(s) defined in this module, initialize the client with an instance of
123    //! this mock in their tests, and verify their application responds as expected.
124    pub use crate::control::stub::*;
125    pub use crate::storage::stub::*;
126    pub use crate::storage::transport::Storage as DefaultStorage;
127}
128
129#[allow(dead_code)]
130pub(crate) mod generated;
131
132#[allow(dead_code)]
133pub(crate) mod google {
134    pub mod iam {
135        pub mod v1 {
136            include!("generated/protos/storage/google.iam.v1.rs");
137            include!("generated/convert/iam/convert.rs");
138        }
139    }
140    pub mod longrunning {
141        include!("generated/protos/control/google.longrunning.rs");
142        include!("generated/convert/longrunning/convert.rs");
143    }
144    pub(crate) mod control_type {
145        // google.storage.v2.control uses a different set of types from google.type vs.
146        // google.storage.v2. We need to define them in a separate module to avoid conflicts and
147        // manually re-export some key symbols.
148        include!("generated/protos/control/google.r#type.rs");
149    }
150    pub mod r#type {
151        // Re-export the google.type.Interval type generated for storage control. Unfortunately
152        // none of the tonic-generated files has all the types from google.type that we need.
153        pub use super::control_type::Interval;
154        include!("generated/protos/storage/google.r#type.rs");
155        include!("generated/convert/type/convert.rs");
156    }
157    pub mod rpc {
158        include!("generated/protos/storage/google.rpc.rs");
159    }
160    pub mod storage {
161        #[allow(deprecated)]
162        #[allow(clippy::large_enum_variant)]
163        pub mod v2 {
164            include!("generated/protos/storage/google.storage.v2.rs");
165            include!("generated/convert/storage/convert.rs");
166        }
167        pub mod control {
168            pub mod v2 {
169                include!("generated/protos/control/google.storage.control.v2.rs");
170                include!("generated/convert/control/convert.rs");
171            }
172        }
173    }
174    #[allow(unused_imports)]
175    pub mod protobuf {
176        pub use gaxi::prost::Empty;
177    }
178}