Skip to main content

opendal/
lib.rs

1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18#![doc(
19    html_logo_url = "https://raw.githubusercontent.com/apache/opendal/main/website/static/img/logo.svg"
20)]
21#![doc = include_str!("../README.md")]
22#![cfg_attr(docsrs, feature(doc_cfg))]
23#![cfg_attr(docsrs, doc(auto_cfg))]
24#![deny(missing_docs)]
25
26pub use opendal_core::*;
27
28#[cfg(feature = "tests")]
29pub extern crate opendal_testkit as tests;
30
31/// Install the global defaults provided by the facade crate.
32///
33/// This function is safe to call multiple times. It registers enabled services
34/// and installs the default HTTP transport when the corresponding feature is
35/// enabled.
36///
37/// # Process-wide HTTP transport
38///
39/// When `auto-register-services` is enabled, a process constructor calls this
40/// function before `main`. If a default HTTP transport feature is also enabled,
41/// that transport occupies the process-wide default because
42/// [`HttpTransporter::install_default`] uses first-installed-wins semantics.
43///
44/// Applications that need to install their own process-wide transport should
45/// disable `auto-register-services`, call [`init_default_registry`] explicitly
46/// when URI-based construction is needed, and install the transport themselves.
47/// Per-operator transports can be configured regardless of this setting.
48pub fn install_default() {
49    init_default_registry();
50
51    #[cfg(feature = "http-transport-reqwest")]
52    opendal_http_transport_reqwest::install_default();
53}
54
55/// Initialize the global [`OperatorRegistry`] with enabled services.
56///
57/// This function is safe to call multiple times and will only perform
58/// initialization once.
59///
60/// # Notes
61///
62/// Some bindings link `opendal` as a `staticlib`, where `#[ctor::ctor]`
63/// initializers may not be executed due to linker behavior. Those bindings
64/// should call this function explicitly before using `Operator::from_uri` or
65/// `Operator::via_iter`.
66pub fn init_default_registry() {
67    static DEFAULT_REGISTRY_INIT: std::sync::Once = std::sync::Once::new();
68    DEFAULT_REGISTRY_INIT.call_once(|| init_default_registry_inner(OperatorRegistry::get()));
69}
70
71fn init_default_registry_inner(registry: &OperatorRegistry) {
72    opendal_core::services::register_memory_service(registry);
73
74    #[cfg(feature = "services-aliyun-drive")]
75    opendal_service_aliyun_drive::register_aliyun_drive_service(registry);
76
77    #[cfg(feature = "services-alluxio")]
78    opendal_service_alluxio::register_alluxio_service(registry);
79
80    #[cfg(feature = "services-azblob")]
81    opendal_service_azblob::register_azblob_service(registry);
82
83    #[cfg(feature = "services-azdls")]
84    opendal_service_azdls::register_azdls_service(registry);
85
86    #[cfg(feature = "services-azfile")]
87    opendal_service_azfile::register_azfile_service(registry);
88
89    #[cfg(feature = "services-b2")]
90    opendal_service_b2::register_b2_service(registry);
91
92    #[cfg(feature = "services-cacache")]
93    opendal_service_cacache::register_cacache_service(registry);
94
95    #[cfg(feature = "services-cloudflare-kv")]
96    opendal_service_cloudflare_kv::register_cloudflare_kv_service(registry);
97
98    #[cfg(feature = "services-compfs")]
99    opendal_service_compfs::register_compfs_service(registry);
100
101    #[cfg(feature = "services-cos")]
102    opendal_service_cos::register_cos_service(registry);
103
104    #[cfg(feature = "services-d1")]
105    opendal_service_d1::register_d1_service(registry);
106
107    #[cfg(feature = "services-dashmap")]
108    opendal_service_dashmap::register_dashmap_service(registry);
109
110    #[cfg(feature = "services-dbfs")]
111    opendal_service_dbfs::register_dbfs_service(registry);
112
113    #[cfg(feature = "services-dropbox")]
114    opendal_service_dropbox::register_dropbox_service(registry);
115
116    #[cfg(feature = "services-etcd")]
117    opendal_service_etcd::register_etcd_service(registry);
118
119    #[cfg(feature = "services-foundationdb")]
120    opendal_service_foundationdb::register_foundationdb_service(registry);
121
122    #[cfg(feature = "services-foyer")]
123    opendal_service_foyer::register_foyer_service(registry);
124
125    #[cfg(feature = "services-fs")]
126    opendal_service_fs::register_fs_service(registry);
127
128    #[cfg(feature = "services-ftp")]
129    opendal_service_ftp::register_ftp_service(registry);
130
131    #[cfg(feature = "services-gcs")]
132    opendal_service_gcs::register_gcs_service(registry);
133
134    #[cfg(feature = "services-gcs-grpc")]
135    opendal_service_gcs_grpc::register_gcs_grpc_service(registry);
136
137    #[cfg(feature = "services-gdrive")]
138    opendal_service_gdrive::register_gdrive_service(registry);
139
140    #[cfg(feature = "services-ghac")]
141    opendal_service_ghac::register_ghac_service(registry);
142
143    #[cfg(feature = "services-github")]
144    opendal_service_github::register_github_service(registry);
145
146    #[cfg(feature = "services-goosefs")]
147    opendal_service_goosefs::register_goosefs_service(registry);
148
149    #[cfg(feature = "services-gridfs")]
150    opendal_service_gridfs::register_gridfs_service(registry);
151
152    #[cfg(feature = "services-hdfs")]
153    opendal_service_hdfs::register_hdfs_service(registry);
154
155    #[cfg(feature = "services-hdfs-native")]
156    opendal_service_hdfs_native::register_hdfs_native_service(registry);
157
158    #[cfg(feature = "services-http")]
159    opendal_service_http::register_http_service(registry);
160
161    #[cfg(feature = "services-hf")]
162    opendal_service_hf::register_hf_service(registry);
163
164    #[cfg(feature = "services-ipfs")]
165    opendal_service_ipfs::register_ipfs_service(registry);
166
167    #[cfg(feature = "services-ipmfs")]
168    opendal_service_ipmfs::register_ipmfs_service(registry);
169
170    #[cfg(feature = "services-koofr")]
171    opendal_service_koofr::register_koofr_service(registry);
172
173    #[cfg(feature = "services-lakefs")]
174    opendal_service_lakefs::register_lakefs_service(registry);
175
176    #[cfg(feature = "services-memcached")]
177    opendal_service_memcached::register_memcached_service(registry);
178
179    #[cfg(feature = "services-mini-moka")]
180    opendal_service_mini_moka::register_mini_moka_service(registry);
181
182    #[cfg(feature = "services-moka")]
183    opendal_service_moka::register_moka_service(registry);
184
185    #[cfg(feature = "services-mongodb")]
186    opendal_service_mongodb::register_mongodb_service(registry);
187
188    #[cfg(feature = "services-monoiofs")]
189    opendal_service_monoiofs::register_monoiofs_service(registry);
190
191    #[cfg(feature = "services-mysql")]
192    opendal_service_mysql::register_mysql_service(registry);
193
194    #[cfg(feature = "services-obs")]
195    opendal_service_obs::register_obs_service(registry);
196
197    #[cfg(feature = "services-onedrive")]
198    opendal_service_onedrive::register_onedrive_service(registry);
199
200    #[cfg(feature = "services-oss")]
201    opendal_service_oss::register_oss_service(registry);
202
203    #[cfg(feature = "services-pcloud")]
204    opendal_service_pcloud::register_pcloud_service(registry);
205
206    #[cfg(feature = "services-persy")]
207    opendal_service_persy::register_persy_service(registry);
208
209    #[cfg(feature = "services-postgresql")]
210    opendal_service_postgresql::register_postgresql_service(registry);
211
212    #[cfg(feature = "services-redb")]
213    opendal_service_redb::register_redb_service(registry);
214
215    #[cfg(feature = "services-rocksdb")]
216    opendal_service_rocksdb::register_rocksdb_service(registry);
217
218    #[cfg(feature = "services-s3")]
219    opendal_service_s3::register_s3_service(registry);
220
221    #[cfg(feature = "services-seafile")]
222    opendal_service_seafile::register_seafile_service(registry);
223
224    #[cfg(feature = "services-sftp")]
225    opendal_service_sftp::register_sftp_service(registry);
226
227    #[cfg(feature = "services-sled")]
228    opendal_service_sled::register_sled_service(registry);
229
230    #[cfg(feature = "services-sqlite")]
231    opendal_service_sqlite::register_sqlite_service(registry);
232
233    #[cfg(feature = "services-surrealdb")]
234    opendal_service_surrealdb::register_surrealdb_service(registry);
235
236    #[cfg(feature = "services-swift")]
237    opendal_service_swift::register_swift_service(registry);
238
239    #[cfg(feature = "services-tikv")]
240    opendal_service_tikv::register_tikv_service(registry);
241
242    #[cfg(feature = "services-tos")]
243    opendal_service_tos::register_tos_service(registry);
244
245    #[cfg(feature = "services-upyun")]
246    opendal_service_upyun::register_upyun_service(registry);
247
248    #[cfg(feature = "services-vercel-artifacts")]
249    opendal_service_vercel_artifacts::register_vercel_artifacts_service(registry);
250
251    #[cfg(feature = "services-vercel-blob")]
252    opendal_service_vercel_blob::register_vercel_blob_service(registry);
253
254    #[cfg(feature = "services-webdav")]
255    opendal_service_webdav::register_webdav_service(registry);
256
257    #[cfg(feature = "services-webhdfs")]
258    opendal_service_webhdfs::register_webhdfs_service(registry);
259
260    #[cfg(feature = "services-yandex-disk")]
261    opendal_service_yandex_disk::register_yandex_disk_service(registry);
262
263    #[cfg(all(target_arch = "wasm32", feature = "services-opfs"))]
264    opendal_service_opfs::register_opfs_service(registry);
265
266    #[cfg(any(feature = "services-redis", feature = "services-redis-native-tls"))]
267    opendal_service_redis::register_redis_service(registry);
268}
269
270#[cfg(feature = "auto-register-services")]
271#[ctor::ctor(unsafe)]
272fn register_default_operator_registry() {
273    install_default();
274}
275
276/// Service builders enabled through `services-*` Cargo features.
277///
278/// [`Memory`](services::Memory) is always available. Other builders are
279/// re-exported when their matching facade feature is enabled; for example,
280/// `services-s3` enables [`S3`](services::S3).
281///
282/// Pass a configured builder to [`Operator::new`]. The facade automatically
283/// registers enabled services for [`Operator::from_uri`] and
284/// [`Operator::via_iter`] when the `auto-register-services` feature is enabled.
285pub mod services {
286    pub use opendal_core::services::*;
287    #[cfg(feature = "services-aliyun-drive")]
288    pub use opendal_service_aliyun_drive::*;
289    #[cfg(feature = "services-alluxio")]
290    pub use opendal_service_alluxio::*;
291    #[cfg(feature = "services-azblob")]
292    pub use opendal_service_azblob::*;
293    #[cfg(feature = "services-azdls")]
294    pub use opendal_service_azdls::*;
295    #[cfg(feature = "services-azfile")]
296    pub use opendal_service_azfile::*;
297    #[cfg(feature = "services-b2")]
298    pub use opendal_service_b2::*;
299    #[cfg(feature = "services-cacache")]
300    pub use opendal_service_cacache::*;
301    #[cfg(feature = "services-cloudflare-kv")]
302    pub use opendal_service_cloudflare_kv::*;
303    #[cfg(feature = "services-compfs")]
304    pub use opendal_service_compfs::*;
305    #[cfg(feature = "services-cos")]
306    pub use opendal_service_cos::*;
307    #[cfg(feature = "services-d1")]
308    pub use opendal_service_d1::*;
309    #[cfg(feature = "services-dashmap")]
310    pub use opendal_service_dashmap::*;
311    #[cfg(feature = "services-dbfs")]
312    pub use opendal_service_dbfs::*;
313    #[cfg(feature = "services-dropbox")]
314    pub use opendal_service_dropbox::*;
315    #[cfg(feature = "services-etcd")]
316    pub use opendal_service_etcd::*;
317    #[cfg(feature = "services-foundationdb")]
318    pub use opendal_service_foundationdb::*;
319    #[cfg(feature = "services-foyer")]
320    pub use opendal_service_foyer::*;
321    #[cfg(feature = "services-fs")]
322    pub use opendal_service_fs::*;
323    #[cfg(feature = "services-ftp")]
324    pub use opendal_service_ftp::*;
325    #[cfg(feature = "services-gcs")]
326    pub use opendal_service_gcs::*;
327    #[cfg(feature = "services-gcs-grpc")]
328    pub use opendal_service_gcs_grpc::*;
329    #[cfg(feature = "services-gdrive")]
330    pub use opendal_service_gdrive::*;
331    #[cfg(feature = "services-ghac")]
332    pub use opendal_service_ghac::*;
333    #[cfg(feature = "services-github")]
334    pub use opendal_service_github::*;
335    #[cfg(feature = "services-goosefs")]
336    pub use opendal_service_goosefs::*;
337    #[cfg(feature = "services-gridfs")]
338    pub use opendal_service_gridfs::*;
339    #[cfg(feature = "services-hdfs")]
340    pub use opendal_service_hdfs::*;
341    #[cfg(feature = "services-hdfs-native")]
342    pub use opendal_service_hdfs_native::*;
343    #[cfg(feature = "services-hf")]
344    pub use opendal_service_hf::*;
345    #[cfg(feature = "services-http")]
346    pub use opendal_service_http::*;
347    #[cfg(feature = "services-ipfs")]
348    pub use opendal_service_ipfs::*;
349    #[cfg(feature = "services-ipmfs")]
350    pub use opendal_service_ipmfs::*;
351    #[cfg(feature = "services-koofr")]
352    pub use opendal_service_koofr::*;
353    #[cfg(feature = "services-lakefs")]
354    pub use opendal_service_lakefs::*;
355    #[cfg(feature = "services-memcached")]
356    pub use opendal_service_memcached::*;
357    #[cfg(feature = "services-mini-moka")]
358    pub use opendal_service_mini_moka::*;
359    #[cfg(feature = "services-moka")]
360    pub use opendal_service_moka::*;
361    #[cfg(feature = "services-mongodb")]
362    pub use opendal_service_mongodb::*;
363    #[cfg(feature = "services-monoiofs")]
364    pub use opendal_service_monoiofs::*;
365    #[cfg(feature = "services-mysql")]
366    pub use opendal_service_mysql::*;
367    #[cfg(feature = "services-obs")]
368    pub use opendal_service_obs::*;
369    #[cfg(feature = "services-onedrive")]
370    pub use opendal_service_onedrive::*;
371    #[cfg(all(target_arch = "wasm32", feature = "services-opfs"))]
372    pub use opendal_service_opfs::*;
373    #[cfg(feature = "services-oss")]
374    pub use opendal_service_oss::*;
375    #[cfg(feature = "services-pcloud")]
376    pub use opendal_service_pcloud::*;
377    #[cfg(feature = "services-persy")]
378    pub use opendal_service_persy::*;
379    #[cfg(feature = "services-postgresql")]
380    pub use opendal_service_postgresql::*;
381    #[cfg(feature = "services-redb")]
382    pub use opendal_service_redb::*;
383    #[cfg(feature = "services-redis")]
384    pub use opendal_service_redis::*;
385    #[cfg(feature = "services-rocksdb")]
386    pub use opendal_service_rocksdb::*;
387    #[cfg(feature = "services-s3")]
388    pub use opendal_service_s3::*;
389    #[cfg(feature = "services-seafile")]
390    pub use opendal_service_seafile::*;
391    #[cfg(feature = "services-sftp")]
392    pub use opendal_service_sftp::*;
393    #[cfg(feature = "services-sled")]
394    pub use opendal_service_sled::*;
395    #[cfg(feature = "services-sqlite")]
396    pub use opendal_service_sqlite::*;
397    #[cfg(feature = "services-surrealdb")]
398    pub use opendal_service_surrealdb::*;
399    #[cfg(feature = "services-swift")]
400    pub use opendal_service_swift::*;
401    #[cfg(feature = "services-tikv")]
402    pub use opendal_service_tikv::*;
403    #[cfg(feature = "services-tos")]
404    pub use opendal_service_tos::*;
405    #[cfg(feature = "services-upyun")]
406    pub use opendal_service_upyun::*;
407    #[cfg(feature = "services-vercel-artifacts")]
408    pub use opendal_service_vercel_artifacts::*;
409    #[cfg(feature = "services-vercel-blob")]
410    pub use opendal_service_vercel_blob::*;
411    #[cfg(feature = "services-webdav")]
412    pub use opendal_service_webdav::*;
413    #[cfg(feature = "services-webhdfs")]
414    pub use opendal_service_webhdfs::*;
415    #[cfg(feature = "services-yandex-disk")]
416    pub use opendal_service_yandex_disk::*;
417}
418
419/// Layers enabled through `layers-*` Cargo features.
420///
421/// A layer adds cross-service behavior to an [`Operator`]. Enable the matching
422/// facade feature, construct the layer, and pass it to [`Operator::layer`].
423/// Layer order is observable, so review each layer's composition notes when
424/// combining retries, timeouts, caching, or observability.
425pub mod layers {
426    pub use opendal_core::layers::*;
427    #[cfg(feature = "layers-async-backtrace")]
428    pub use opendal_layer_async_backtrace::*;
429    #[cfg(feature = "layers-await-tree")]
430    pub use opendal_layer_await_tree::*;
431    #[cfg(feature = "layers-capability-check")]
432    pub use opendal_layer_capability_check::*;
433    #[cfg(feature = "layers-chaos")]
434    pub use opendal_layer_chaos::*;
435    #[cfg(feature = "layers-concurrent-limit")]
436    pub use opendal_layer_concurrent_limit::*;
437    #[cfg(all(target_os = "linux", feature = "layers-dtrace"))]
438    pub use opendal_layer_dtrace::*;
439    #[cfg(feature = "layers-fastmetrics")]
440    pub use opendal_layer_fastmetrics::*;
441    #[cfg(feature = "layers-fastrace")]
442    pub use opendal_layer_fastrace::*;
443    #[cfg(feature = "layers-foyer")]
444    pub use opendal_layer_foyer::*;
445    #[cfg(feature = "layers-hotpath")]
446    pub use opendal_layer_hotpath::*;
447    #[cfg(feature = "layers-immutable-index")]
448    pub use opendal_layer_immutable_index::*;
449    #[cfg(feature = "layers-logging")]
450    pub use opendal_layer_logging::*;
451    #[cfg(feature = "layers-metrics")]
452    pub use opendal_layer_metrics::*;
453    #[cfg(feature = "layers-mime-guess")]
454    pub use opendal_layer_mime_guess::*;
455    #[cfg(feature = "layers-otel-metrics")]
456    pub use opendal_layer_otelmetrics::*;
457    #[cfg(feature = "layers-otel-trace")]
458    pub use opendal_layer_oteltrace::*;
459    #[cfg(feature = "layers-prometheus")]
460    pub use opendal_layer_prometheus::*;
461    #[cfg(feature = "layers-prometheus-client")]
462    pub use opendal_layer_prometheus_client::*;
463    #[cfg(feature = "layers-retry")]
464    pub use opendal_layer_retry::*;
465    #[cfg(feature = "layers-route")]
466    pub use opendal_layer_route::*;
467    #[cfg(feature = "layers-tail-cut")]
468    pub use opendal_layer_tail_cut::*;
469    #[cfg(feature = "layers-throttle")]
470    pub use opendal_layer_throttle::*;
471    #[cfg(feature = "layers-timeout")]
472    pub use opendal_layer_timeout::*;
473    #[cfg(feature = "layers-tracing")]
474    pub use opendal_layer_tracing::*;
475}