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-gdrive")]
135    opendal_service_gdrive::register_gdrive_service(registry);
136
137    #[cfg(feature = "services-ghac")]
138    opendal_service_ghac::register_ghac_service(registry);
139
140    #[cfg(feature = "services-github")]
141    opendal_service_github::register_github_service(registry);
142
143    #[cfg(feature = "services-goosefs")]
144    opendal_service_goosefs::register_goosefs_service(registry);
145
146    #[cfg(feature = "services-gridfs")]
147    opendal_service_gridfs::register_gridfs_service(registry);
148
149    #[cfg(feature = "services-hdfs")]
150    opendal_service_hdfs::register_hdfs_service(registry);
151
152    #[cfg(feature = "services-hdfs-native")]
153    opendal_service_hdfs_native::register_hdfs_native_service(registry);
154
155    #[cfg(feature = "services-http")]
156    opendal_service_http::register_http_service(registry);
157
158    #[cfg(feature = "services-hf")]
159    opendal_service_hf::register_hf_service(registry);
160
161    #[cfg(feature = "services-ipfs")]
162    opendal_service_ipfs::register_ipfs_service(registry);
163
164    #[cfg(feature = "services-ipmfs")]
165    opendal_service_ipmfs::register_ipmfs_service(registry);
166
167    #[cfg(feature = "services-koofr")]
168    opendal_service_koofr::register_koofr_service(registry);
169
170    #[cfg(feature = "services-lakefs")]
171    opendal_service_lakefs::register_lakefs_service(registry);
172
173    #[cfg(feature = "services-memcached")]
174    opendal_service_memcached::register_memcached_service(registry);
175
176    #[cfg(feature = "services-mini-moka")]
177    opendal_service_mini_moka::register_mini_moka_service(registry);
178
179    #[cfg(feature = "services-moka")]
180    opendal_service_moka::register_moka_service(registry);
181
182    #[cfg(feature = "services-mongodb")]
183    opendal_service_mongodb::register_mongodb_service(registry);
184
185    #[cfg(feature = "services-monoiofs")]
186    opendal_service_monoiofs::register_monoiofs_service(registry);
187
188    #[cfg(feature = "services-mysql")]
189    opendal_service_mysql::register_mysql_service(registry);
190
191    #[cfg(feature = "services-obs")]
192    opendal_service_obs::register_obs_service(registry);
193
194    #[cfg(feature = "services-onedrive")]
195    opendal_service_onedrive::register_onedrive_service(registry);
196
197    #[cfg(feature = "services-oss")]
198    opendal_service_oss::register_oss_service(registry);
199
200    #[cfg(feature = "services-pcloud")]
201    opendal_service_pcloud::register_pcloud_service(registry);
202
203    #[cfg(feature = "services-persy")]
204    opendal_service_persy::register_persy_service(registry);
205
206    #[cfg(feature = "services-postgresql")]
207    opendal_service_postgresql::register_postgresql_service(registry);
208
209    #[cfg(feature = "services-redb")]
210    opendal_service_redb::register_redb_service(registry);
211
212    #[cfg(feature = "services-rocksdb")]
213    opendal_service_rocksdb::register_rocksdb_service(registry);
214
215    #[cfg(feature = "services-s3")]
216    opendal_service_s3::register_s3_service(registry);
217
218    #[cfg(feature = "services-seafile")]
219    opendal_service_seafile::register_seafile_service(registry);
220
221    #[cfg(feature = "services-sftp")]
222    opendal_service_sftp::register_sftp_service(registry);
223
224    #[cfg(feature = "services-sled")]
225    opendal_service_sled::register_sled_service(registry);
226
227    #[cfg(feature = "services-sqlite")]
228    opendal_service_sqlite::register_sqlite_service(registry);
229
230    #[cfg(feature = "services-surrealdb")]
231    opendal_service_surrealdb::register_surrealdb_service(registry);
232
233    #[cfg(feature = "services-swift")]
234    opendal_service_swift::register_swift_service(registry);
235
236    #[cfg(feature = "services-tikv")]
237    opendal_service_tikv::register_tikv_service(registry);
238
239    #[cfg(feature = "services-tos")]
240    opendal_service_tos::register_tos_service(registry);
241
242    #[cfg(feature = "services-upyun")]
243    opendal_service_upyun::register_upyun_service(registry);
244
245    #[cfg(feature = "services-vercel-artifacts")]
246    opendal_service_vercel_artifacts::register_vercel_artifacts_service(registry);
247
248    #[cfg(feature = "services-vercel-blob")]
249    opendal_service_vercel_blob::register_vercel_blob_service(registry);
250
251    #[cfg(feature = "services-webdav")]
252    opendal_service_webdav::register_webdav_service(registry);
253
254    #[cfg(feature = "services-webhdfs")]
255    opendal_service_webhdfs::register_webhdfs_service(registry);
256
257    #[cfg(feature = "services-yandex-disk")]
258    opendal_service_yandex_disk::register_yandex_disk_service(registry);
259
260    #[cfg(all(target_arch = "wasm32", feature = "services-opfs"))]
261    opendal_service_opfs::register_opfs_service(registry);
262
263    #[cfg(any(feature = "services-redis", feature = "services-redis-native-tls"))]
264    opendal_service_redis::register_redis_service(registry);
265}
266
267#[cfg(feature = "auto-register-services")]
268#[ctor::ctor(unsafe)]
269fn register_default_operator_registry() {
270    install_default();
271}
272
273/// Service builders enabled through `services-*` Cargo features.
274///
275/// [`Memory`](services::Memory) is always available. Other builders are
276/// re-exported when their matching facade feature is enabled; for example,
277/// `services-s3` enables [`S3`](services::S3).
278///
279/// Pass a configured builder to [`Operator::new`]. The facade automatically
280/// registers enabled services for [`Operator::from_uri`] and
281/// [`Operator::via_iter`] when the `auto-register-services` feature is enabled.
282pub mod services {
283    pub use opendal_core::services::*;
284    #[cfg(feature = "services-aliyun-drive")]
285    pub use opendal_service_aliyun_drive::*;
286    #[cfg(feature = "services-alluxio")]
287    pub use opendal_service_alluxio::*;
288    #[cfg(feature = "services-azblob")]
289    pub use opendal_service_azblob::*;
290    #[cfg(feature = "services-azdls")]
291    pub use opendal_service_azdls::*;
292    #[cfg(feature = "services-azfile")]
293    pub use opendal_service_azfile::*;
294    #[cfg(feature = "services-b2")]
295    pub use opendal_service_b2::*;
296    #[cfg(feature = "services-cacache")]
297    pub use opendal_service_cacache::*;
298    #[cfg(feature = "services-cloudflare-kv")]
299    pub use opendal_service_cloudflare_kv::*;
300    #[cfg(feature = "services-compfs")]
301    pub use opendal_service_compfs::*;
302    #[cfg(feature = "services-cos")]
303    pub use opendal_service_cos::*;
304    #[cfg(feature = "services-d1")]
305    pub use opendal_service_d1::*;
306    #[cfg(feature = "services-dashmap")]
307    pub use opendal_service_dashmap::*;
308    #[cfg(feature = "services-dbfs")]
309    pub use opendal_service_dbfs::*;
310    #[cfg(feature = "services-dropbox")]
311    pub use opendal_service_dropbox::*;
312    #[cfg(feature = "services-etcd")]
313    pub use opendal_service_etcd::*;
314    #[cfg(feature = "services-foundationdb")]
315    pub use opendal_service_foundationdb::*;
316    #[cfg(feature = "services-foyer")]
317    pub use opendal_service_foyer::*;
318    #[cfg(feature = "services-fs")]
319    pub use opendal_service_fs::*;
320    #[cfg(feature = "services-ftp")]
321    pub use opendal_service_ftp::*;
322    #[cfg(feature = "services-gcs")]
323    pub use opendal_service_gcs::*;
324    #[cfg(feature = "services-gdrive")]
325    pub use opendal_service_gdrive::*;
326    #[cfg(feature = "services-ghac")]
327    pub use opendal_service_ghac::*;
328    #[cfg(feature = "services-github")]
329    pub use opendal_service_github::*;
330    #[cfg(feature = "services-goosefs")]
331    pub use opendal_service_goosefs::*;
332    #[cfg(feature = "services-gridfs")]
333    pub use opendal_service_gridfs::*;
334    #[cfg(feature = "services-hdfs")]
335    pub use opendal_service_hdfs::*;
336    #[cfg(feature = "services-hdfs-native")]
337    pub use opendal_service_hdfs_native::*;
338    #[cfg(feature = "services-hf")]
339    pub use opendal_service_hf::*;
340    #[cfg(feature = "services-http")]
341    pub use opendal_service_http::*;
342    #[cfg(feature = "services-ipfs")]
343    pub use opendal_service_ipfs::*;
344    #[cfg(feature = "services-ipmfs")]
345    pub use opendal_service_ipmfs::*;
346    #[cfg(feature = "services-koofr")]
347    pub use opendal_service_koofr::*;
348    #[cfg(feature = "services-lakefs")]
349    pub use opendal_service_lakefs::*;
350    #[cfg(feature = "services-memcached")]
351    pub use opendal_service_memcached::*;
352    #[cfg(feature = "services-mini-moka")]
353    pub use opendal_service_mini_moka::*;
354    #[cfg(feature = "services-moka")]
355    pub use opendal_service_moka::*;
356    #[cfg(feature = "services-mongodb")]
357    pub use opendal_service_mongodb::*;
358    #[cfg(feature = "services-monoiofs")]
359    pub use opendal_service_monoiofs::*;
360    #[cfg(feature = "services-mysql")]
361    pub use opendal_service_mysql::*;
362    #[cfg(feature = "services-obs")]
363    pub use opendal_service_obs::*;
364    #[cfg(feature = "services-onedrive")]
365    pub use opendal_service_onedrive::*;
366    #[cfg(all(target_arch = "wasm32", feature = "services-opfs"))]
367    pub use opendal_service_opfs::*;
368    #[cfg(feature = "services-oss")]
369    pub use opendal_service_oss::*;
370    #[cfg(feature = "services-pcloud")]
371    pub use opendal_service_pcloud::*;
372    #[cfg(feature = "services-persy")]
373    pub use opendal_service_persy::*;
374    #[cfg(feature = "services-postgresql")]
375    pub use opendal_service_postgresql::*;
376    #[cfg(feature = "services-redb")]
377    pub use opendal_service_redb::*;
378    #[cfg(feature = "services-redis")]
379    pub use opendal_service_redis::*;
380    #[cfg(feature = "services-rocksdb")]
381    pub use opendal_service_rocksdb::*;
382    #[cfg(feature = "services-s3")]
383    pub use opendal_service_s3::*;
384    #[cfg(feature = "services-seafile")]
385    pub use opendal_service_seafile::*;
386    #[cfg(feature = "services-sftp")]
387    pub use opendal_service_sftp::*;
388    #[cfg(feature = "services-sled")]
389    pub use opendal_service_sled::*;
390    #[cfg(feature = "services-sqlite")]
391    pub use opendal_service_sqlite::*;
392    #[cfg(feature = "services-surrealdb")]
393    pub use opendal_service_surrealdb::*;
394    #[cfg(feature = "services-swift")]
395    pub use opendal_service_swift::*;
396    #[cfg(feature = "services-tikv")]
397    pub use opendal_service_tikv::*;
398    #[cfg(feature = "services-tos")]
399    pub use opendal_service_tos::*;
400    #[cfg(feature = "services-upyun")]
401    pub use opendal_service_upyun::*;
402    #[cfg(feature = "services-vercel-artifacts")]
403    pub use opendal_service_vercel_artifacts::*;
404    #[cfg(feature = "services-vercel-blob")]
405    pub use opendal_service_vercel_blob::*;
406    #[cfg(feature = "services-webdav")]
407    pub use opendal_service_webdav::*;
408    #[cfg(feature = "services-webhdfs")]
409    pub use opendal_service_webhdfs::*;
410    #[cfg(feature = "services-yandex-disk")]
411    pub use opendal_service_yandex_disk::*;
412}
413
414/// Layers enabled through `layers-*` Cargo features.
415///
416/// A layer adds cross-service behavior to an [`Operator`]. Enable the matching
417/// facade feature, construct the layer, and pass it to [`Operator::layer`].
418/// Layer order is observable, so review each layer's composition notes when
419/// combining retries, timeouts, caching, or observability.
420pub mod layers {
421    pub use opendal_core::layers::*;
422    #[cfg(feature = "layers-async-backtrace")]
423    pub use opendal_layer_async_backtrace::*;
424    #[cfg(feature = "layers-await-tree")]
425    pub use opendal_layer_await_tree::*;
426    #[cfg(feature = "layers-capability-check")]
427    pub use opendal_layer_capability_check::*;
428    #[cfg(feature = "layers-chaos")]
429    pub use opendal_layer_chaos::*;
430    #[cfg(feature = "layers-concurrent-limit")]
431    pub use opendal_layer_concurrent_limit::*;
432    #[cfg(all(target_os = "linux", feature = "layers-dtrace"))]
433    pub use opendal_layer_dtrace::*;
434    #[cfg(feature = "layers-fastmetrics")]
435    pub use opendal_layer_fastmetrics::*;
436    #[cfg(feature = "layers-fastrace")]
437    pub use opendal_layer_fastrace::*;
438    #[cfg(feature = "layers-foyer")]
439    pub use opendal_layer_foyer::*;
440    #[cfg(feature = "layers-hotpath")]
441    pub use opendal_layer_hotpath::*;
442    #[cfg(feature = "layers-immutable-index")]
443    pub use opendal_layer_immutable_index::*;
444    #[cfg(feature = "layers-logging")]
445    pub use opendal_layer_logging::*;
446    #[cfg(feature = "layers-metrics")]
447    pub use opendal_layer_metrics::*;
448    #[cfg(feature = "layers-mime-guess")]
449    pub use opendal_layer_mime_guess::*;
450    #[cfg(feature = "layers-otel-metrics")]
451    pub use opendal_layer_otelmetrics::*;
452    #[cfg(feature = "layers-otel-trace")]
453    pub use opendal_layer_oteltrace::*;
454    #[cfg(feature = "layers-prometheus")]
455    pub use opendal_layer_prometheus::*;
456    #[cfg(feature = "layers-prometheus-client")]
457    pub use opendal_layer_prometheus_client::*;
458    #[cfg(feature = "layers-retry")]
459    pub use opendal_layer_retry::*;
460    #[cfg(feature = "layers-route")]
461    pub use opendal_layer_route::*;
462    #[cfg(feature = "layers-tail-cut")]
463    pub use opendal_layer_tail_cut::*;
464    #[cfg(feature = "layers-throttle")]
465    pub use opendal_layer_throttle::*;
466    #[cfg(feature = "layers-timeout")]
467    pub use opendal_layer_timeout::*;
468    #[cfg(feature = "layers-tracing")]
469    pub use opendal_layer_tracing::*;
470}