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