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