opendal/types/
scheme.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
18use std::collections::HashSet;
19use std::fmt::Display;
20use std::fmt::Formatter;
21use std::str::FromStr;
22
23use crate::Error;
24
25/// Services that OpenDAL supports
26///
27/// # Notes
28///
29/// - Scheme is `non_exhaustive`, new variant COULD be added at any time.
30/// - New variant SHOULD be added in alphabet orders,
31/// - Users MUST NOT relay on its order.
32#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
33#[non_exhaustive]
34pub enum Scheme {
35    /// [aliyun_drive][crate::services::AliyunDrive]: Aliyun Drive services.
36    AliyunDrive,
37    /// [atomicserver][crate::services::Atomicserver]: Atomicserver services.
38    Atomicserver,
39    /// [azblob][crate::services::Azblob]: Azure Storage Blob services.
40    Azblob,
41    /// [Azdls][crate::services::Azdls]: Azure Data Lake Storage Gen2.
42    Azdls,
43    /// [B2][crate::services::B2]: Backblaze B2 Services.
44    B2,
45    /// [Compfs][crate::services::Compfs]: Compio fs Services.
46    Compfs,
47    /// [Seafile][crate::services::Seafile]: Seafile Services.
48    Seafile,
49    /// [Upyun][crate::services::Upyun]: Upyun Services.
50    Upyun,
51    /// [VercelBlob][crate::services::VercelBlob]: VercelBlob Services.
52    VercelBlob,
53    /// [YandexDisk][crate::services::YandexDisk]: YandexDisk Services.
54    YandexDisk,
55    /// [Pcloud][crate::services::Pcloud]: Pcloud Services.
56    Pcloud,
57    /// [Koofr][crate::services::Koofr]: Koofr Services.
58    Koofr,
59    /// [cacache][crate::services::Cacache]: cacache backend support.
60    Cacache,
61    /// [cloudflare-kv][crate::services::CloudflareKv]: Cloudflare KV services.
62    CloudflareKv,
63    /// [cos][crate::services::Cos]: Tencent Cloud Object Storage services.
64    Cos,
65    /// [d1][crate::services::D1]: D1 services
66    D1,
67    /// [dashmap][crate::services::Dashmap]: dashmap backend support.
68    Dashmap,
69    /// [etcd][crate::services::Etcd]: Etcd Services
70    Etcd,
71    /// [foundationdb][crate::services::Foundationdb]: Foundationdb services.
72    Foundationdb,
73    /// [dbfs][crate::services::Dbfs]: DBFS backend support.
74    Dbfs,
75    /// [fs][crate::services::Fs]: POSIX-like file system.
76    Fs,
77    /// [ftp][crate::services::Ftp]: FTP backend.
78    Ftp,
79    /// [gcs][crate::services::Gcs]: Google Cloud Storage backend.
80    Gcs,
81    /// [ghac][crate::services::Ghac]: GitHub Action Cache services.
82    Ghac,
83    /// [hdfs][crate::services::Hdfs]: Hadoop Distributed File System.
84    Hdfs,
85    /// [http][crate::services::Http]: HTTP backend.
86    Http,
87    /// [huggingface][crate::services::Huggingface]: Huggingface services.
88    Huggingface,
89    /// [alluxio][crate::services::Alluxio]: Alluxio services.
90    Alluxio,
91
92    /// [ipmfs][crate::services::Ipfs]: IPFS HTTP Gateway
93    Ipfs,
94    /// [ipmfs][crate::services::Ipmfs]: IPFS mutable file system
95    Ipmfs,
96    /// [icloud][crate::services::Icloud]: APPLE icloud services.
97    Icloud,
98    /// [memcached][crate::services::Memcached]: Memcached service support.
99    Memcached,
100    /// [memory][crate::services::Memory]: In memory backend support.
101    Memory,
102    /// [mini-moka][crate::services::MiniMoka]: Mini Moka backend support.
103    MiniMoka,
104    /// [moka][crate::services::Moka]: moka backend support.
105    Moka,
106    /// [monoiofs][crate::services::Monoiofs]: monoio fs services.
107    Monoiofs,
108    /// [obs][crate::services::Obs]: Huawei Cloud OBS services.
109    Obs,
110    /// [onedrive][crate::services::Onedrive]: Microsoft OneDrive services.
111    Onedrive,
112    /// [gdrive][crate::services::Gdrive]: GoogleDrive services.
113    Gdrive,
114    /// [dropbox][crate::services::Dropbox]: Dropbox services.
115    Dropbox,
116    /// [oss][crate::services::Oss]: Aliyun Object Storage Services
117    Oss,
118    /// [persy][crate::services::Persy]: persy backend support.
119    Persy,
120    /// [redis][crate::services::Redis]: Redis services
121    Redis,
122    /// [postgresql][crate::services::Postgresql]: Postgresql services
123    Postgresql,
124    /// [mysql][crate::services::Mysql]: Mysql services
125    Mysql,
126    /// [sqlite][crate::services::Sqlite]: Sqlite services
127    Sqlite,
128    /// [rocksdb][crate::services::Rocksdb]: RocksDB services
129    Rocksdb,
130    /// [s3][crate::services::S3]: AWS S3 alike services.
131    S3,
132    /// [sftp][crate::services::Sftp]: SFTP services
133    Sftp,
134    /// [sled][crate::services::Sled]: Sled services
135    Sled,
136    /// [swift][crate::services::Swift]: Swift backend support.
137    Swift,
138    /// [Vercel Artifacts][crate::services::VercelArtifacts]: Vercel Artifacts service, as known as Vercel Remote Caching.
139    VercelArtifacts,
140    /// [webdav][crate::services::Webdav]: WebDAV support.
141    Webdav,
142    /// [webhdfs][crate::services::Webhdfs]: WebHDFS RESTful API Services
143    Webhdfs,
144    /// [redb][crate::services::Redb]: Redb Services
145    Redb,
146    /// [tikv][crate::services::Tikv]: Tikv Services
147    Tikv,
148    /// [azfile][crate::services::Azfile]: Azfile Services
149    Azfile,
150    /// [mongodb](crate::services::Mongodb): MongoDB Services
151    Mongodb,
152    /// [gridfs](crate::services::Gridfs): MongoDB Gridfs Services
153    Gridfs,
154    /// [Github Contents][crate::services::Github]: Github contents support.
155    Github,
156    /// [Native HDFS](crate::services::HdfsNative): Hdfs Native service, using rust hdfs-native client for hdfs
157    HdfsNative,
158    /// [surrealdb](crate::services::Surrealdb): Surrealdb Services
159    Surrealdb,
160    /// [lakefs](crate::services::Lakefs): LakeFS Services
161    Lakefs,
162    /// [NebulaGraph](crate::services::NebulaGraph): NebulaGraph Services
163    NebulaGraph,
164    /// Custom that allow users to implement services outside of OpenDAL.
165    ///
166    /// # NOTE
167    ///
168    /// - Custom must not overwrite any existing services name.
169    /// - Custom must be in lower case.
170    Custom(&'static str),
171}
172
173impl Scheme {
174    /// Convert self into static str.
175    pub fn into_static(self) -> &'static str {
176        self.into()
177    }
178
179    /// Get all enabled schemes.
180    ///
181    /// OpenDAL could be compiled with different features, which will enable different schemes.
182    /// This function returns all enabled schemes so users can make decisions based on it.
183    ///
184    /// # Examples
185    ///
186    /// ```rust,no_run
187    /// use opendal::Scheme;
188    ///
189    /// let enabled_schemes = Scheme::enabled();
190    /// if !enabled_schemes.contains(&Scheme::Memory) {
191    ///     panic!("s3 support is not enabled")
192    /// }
193    /// ```
194    pub fn enabled() -> HashSet<Scheme> {
195        HashSet::from([
196            #[cfg(feature = "services-aliyun-drive")]
197            Scheme::AliyunDrive,
198            #[cfg(feature = "services-atomicserver")]
199            Scheme::Atomicserver,
200            #[cfg(feature = "services-alluxio")]
201            Scheme::Alluxio,
202            #[cfg(feature = "services-azblob")]
203            Scheme::Azblob,
204            #[cfg(feature = "services-azdls")]
205            Scheme::Azdls,
206            #[cfg(feature = "services-azfile")]
207            Scheme::Azfile,
208            #[cfg(feature = "services-b2")]
209            Scheme::B2,
210            #[cfg(feature = "services-cacache")]
211            Scheme::Cacache,
212            #[cfg(feature = "services-cos")]
213            Scheme::Cos,
214            #[cfg(feature = "services-compfs")]
215            Scheme::Compfs,
216            #[cfg(feature = "services-dashmap")]
217            Scheme::Dashmap,
218            #[cfg(feature = "services-dropbox")]
219            Scheme::Dropbox,
220            #[cfg(feature = "services-etcd")]
221            Scheme::Etcd,
222            #[cfg(feature = "services-foundationdb")]
223            Scheme::Foundationdb,
224            #[cfg(feature = "services-fs")]
225            Scheme::Fs,
226            #[cfg(feature = "services-ftp")]
227            Scheme::Ftp,
228            #[cfg(feature = "services-gcs")]
229            Scheme::Gcs,
230            #[cfg(feature = "services-ghac")]
231            Scheme::Ghac,
232            #[cfg(feature = "services-hdfs")]
233            Scheme::Hdfs,
234            #[cfg(feature = "services-http")]
235            Scheme::Http,
236            #[cfg(feature = "services-huggingface")]
237            Scheme::Huggingface,
238            #[cfg(feature = "services-ipfs")]
239            Scheme::Ipfs,
240            #[cfg(feature = "services-ipmfs")]
241            Scheme::Ipmfs,
242            #[cfg(feature = "services-icloud")]
243            Scheme::Icloud,
244            #[cfg(feature = "services-memcached")]
245            Scheme::Memcached,
246            #[cfg(feature = "services-memory")]
247            Scheme::Memory,
248            #[cfg(feature = "services-mini-moka")]
249            Scheme::MiniMoka,
250            #[cfg(feature = "services-moka")]
251            Scheme::Moka,
252            #[cfg(feature = "services-monoiofs")]
253            Scheme::Monoiofs,
254            #[cfg(feature = "services-mysql")]
255            Scheme::Mysql,
256            #[cfg(feature = "services-obs")]
257            Scheme::Obs,
258            #[cfg(feature = "services-onedrive")]
259            Scheme::Onedrive,
260            #[cfg(feature = "services-postgresql")]
261            Scheme::Postgresql,
262            #[cfg(feature = "services-gdrive")]
263            Scheme::Gdrive,
264            #[cfg(feature = "services-oss")]
265            Scheme::Oss,
266            #[cfg(feature = "services-persy")]
267            Scheme::Persy,
268            #[cfg(feature = "services-redis")]
269            Scheme::Redis,
270            #[cfg(feature = "services-rocksdb")]
271            Scheme::Rocksdb,
272            #[cfg(feature = "services-s3")]
273            Scheme::S3,
274            #[cfg(feature = "services-seafile")]
275            Scheme::Seafile,
276            #[cfg(feature = "services-upyun")]
277            Scheme::Upyun,
278            #[cfg(feature = "services-yandex-disk")]
279            Scheme::YandexDisk,
280            #[cfg(feature = "services-pcloud")]
281            Scheme::Pcloud,
282            #[cfg(feature = "services-sftp")]
283            Scheme::Sftp,
284            #[cfg(feature = "services-sled")]
285            Scheme::Sled,
286            #[cfg(feature = "services-sqlite")]
287            Scheme::Sqlite,
288            #[cfg(feature = "services-swift")]
289            Scheme::Swift,
290            #[cfg(feature = "services-tikv")]
291            Scheme::Tikv,
292            #[cfg(feature = "services-vercel-artifacts")]
293            Scheme::VercelArtifacts,
294            #[cfg(feature = "services-vercel-blob")]
295            Scheme::VercelBlob,
296            #[cfg(feature = "services-webdav")]
297            Scheme::Webdav,
298            #[cfg(feature = "services-webhdfs")]
299            Scheme::Webhdfs,
300            #[cfg(feature = "services-redb")]
301            Scheme::Redb,
302            #[cfg(feature = "services-mongodb")]
303            Scheme::Mongodb,
304            #[cfg(feature = "services-hdfs-native")]
305            Scheme::HdfsNative,
306            #[cfg(feature = "services-surrealdb")]
307            Scheme::Surrealdb,
308            #[cfg(feature = "services-lakefs")]
309            Scheme::Lakefs,
310            #[cfg(feature = "services-nebula-graph")]
311            Scheme::NebulaGraph,
312        ])
313    }
314}
315
316impl Default for Scheme {
317    fn default() -> Self {
318        Self::Memory
319    }
320}
321
322impl Display for Scheme {
323    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
324        write!(f, "{}", self.into_static())
325    }
326}
327
328impl FromStr for Scheme {
329    type Err = Error;
330
331    fn from_str(s: &str) -> Result<Self, Self::Err> {
332        let s = s.to_lowercase();
333        match s.as_str() {
334            "aliyun_drive" => Ok(Scheme::AliyunDrive),
335            "atomicserver" => Ok(Scheme::Atomicserver),
336            "azblob" => Ok(Scheme::Azblob),
337            "alluxio" => Ok(Scheme::Alluxio),
338            // Notes:
339            //
340            // OpenDAL used to call `azdls` as `azdfs`, we keep it for backward compatibility.
341            // And abfs is widely used in hadoop ecosystem, keep it for easy to use.
342            "azdls" | "azdfs" | "abfs" => Ok(Scheme::Azdls),
343            "b2" => Ok(Scheme::B2),
344            "cacache" => Ok(Scheme::Cacache),
345            "compfs" => Ok(Scheme::Compfs),
346            "cloudflare_kv" => Ok(Scheme::CloudflareKv),
347            "cos" => Ok(Scheme::Cos),
348            "d1" => Ok(Scheme::D1),
349            "dashmap" => Ok(Scheme::Dashmap),
350            "dropbox" => Ok(Scheme::Dropbox),
351            "etcd" => Ok(Scheme::Etcd),
352            "dbfs" => Ok(Scheme::Dbfs),
353            "fs" => Ok(Scheme::Fs),
354            "gcs" => Ok(Scheme::Gcs),
355            "gdrive" => Ok(Scheme::Gdrive),
356            "ghac" => Ok(Scheme::Ghac),
357            "gridfs" => Ok(Scheme::Gridfs),
358            "github" => Ok(Scheme::Github),
359            "hdfs" => Ok(Scheme::Hdfs),
360            "http" | "https" => Ok(Scheme::Http),
361            "huggingface" | "hf" => Ok(Scheme::Huggingface),
362            "ftp" | "ftps" => Ok(Scheme::Ftp),
363            "ipfs" | "ipns" => Ok(Scheme::Ipfs),
364            "ipmfs" => Ok(Scheme::Ipmfs),
365            "icloud" => Ok(Scheme::Icloud),
366            "koofr" => Ok(Scheme::Koofr),
367            "memcached" => Ok(Scheme::Memcached),
368            "memory" => Ok(Scheme::Memory),
369            "mysql" => Ok(Scheme::Mysql),
370            "sqlite" => Ok(Scheme::Sqlite),
371            "mini_moka" => Ok(Scheme::MiniMoka),
372            "moka" => Ok(Scheme::Moka),
373            "monoiofs" => Ok(Scheme::Monoiofs),
374            "obs" => Ok(Scheme::Obs),
375            "onedrive" => Ok(Scheme::Onedrive),
376            "persy" => Ok(Scheme::Persy),
377            "postgresql" => Ok(Scheme::Postgresql),
378            "redb" => Ok(Scheme::Redb),
379            "redis" => Ok(Scheme::Redis),
380            "rocksdb" => Ok(Scheme::Rocksdb),
381            "s3" => Ok(Scheme::S3),
382            "seafile" => Ok(Scheme::Seafile),
383            "upyun" => Ok(Scheme::Upyun),
384            "yandex_disk" => Ok(Scheme::YandexDisk),
385            "pcloud" => Ok(Scheme::Pcloud),
386            "sftp" => Ok(Scheme::Sftp),
387            "sled" => Ok(Scheme::Sled),
388            "swift" => Ok(Scheme::Swift),
389            "oss" => Ok(Scheme::Oss),
390            "vercel_artifacts" => Ok(Scheme::VercelArtifacts),
391            "vercel_blob" => Ok(Scheme::VercelBlob),
392            "webdav" => Ok(Scheme::Webdav),
393            "webhdfs" => Ok(Scheme::Webhdfs),
394            "tikv" => Ok(Scheme::Tikv),
395            "azfile" => Ok(Scheme::Azfile),
396            "mongodb" => Ok(Scheme::Mongodb),
397            "hdfs_native" => Ok(Scheme::HdfsNative),
398            "surrealdb" => Ok(Scheme::Surrealdb),
399            "lakefs" => Ok(Scheme::Lakefs),
400            "nebula_graph" => Ok(Scheme::NebulaGraph),
401            _ => Ok(Scheme::Custom(Box::leak(s.into_boxed_str()))),
402        }
403    }
404}
405
406impl From<Scheme> for &'static str {
407    fn from(v: Scheme) -> Self {
408        match v {
409            Scheme::AliyunDrive => "aliyun_drive",
410            Scheme::Atomicserver => "atomicserver",
411            Scheme::Azblob => "azblob",
412            Scheme::Azdls => "azdls",
413            Scheme::B2 => "b2",
414            Scheme::Cacache => "cacache",
415            Scheme::CloudflareKv => "cloudflare_kv",
416            Scheme::Cos => "cos",
417            Scheme::Compfs => "compfs",
418            Scheme::D1 => "d1",
419            Scheme::Dashmap => "dashmap",
420            Scheme::Etcd => "etcd",
421            Scheme::Dbfs => "dbfs",
422            Scheme::Fs => "fs",
423            Scheme::Gcs => "gcs",
424            Scheme::Ghac => "ghac",
425            Scheme::Gridfs => "gridfs",
426            Scheme::Hdfs => "hdfs",
427            Scheme::Http => "http",
428            Scheme::Huggingface => "huggingface",
429            Scheme::Foundationdb => "foundationdb",
430            Scheme::Ftp => "ftp",
431            Scheme::Ipfs => "ipfs",
432            Scheme::Ipmfs => "ipmfs",
433            Scheme::Icloud => "icloud",
434            Scheme::Koofr => "koofr",
435            Scheme::Memcached => "memcached",
436            Scheme::Memory => "memory",
437            Scheme::MiniMoka => "mini_moka",
438            Scheme::Moka => "moka",
439            Scheme::Monoiofs => "monoiofs",
440            Scheme::Obs => "obs",
441            Scheme::Onedrive => "onedrive",
442            Scheme::Persy => "persy",
443            Scheme::Postgresql => "postgresql",
444            Scheme::Mysql => "mysql",
445            Scheme::Gdrive => "gdrive",
446            Scheme::Github => "github",
447            Scheme::Dropbox => "dropbox",
448            Scheme::Redis => "redis",
449            Scheme::Rocksdb => "rocksdb",
450            Scheme::S3 => "s3",
451            Scheme::Seafile => "seafile",
452            Scheme::Sftp => "sftp",
453            Scheme::Sled => "sled",
454            Scheme::Swift => "swift",
455            Scheme::VercelArtifacts => "vercel_artifacts",
456            Scheme::VercelBlob => "vercel_blob",
457            Scheme::Oss => "oss",
458            Scheme::Webdav => "webdav",
459            Scheme::Webhdfs => "webhdfs",
460            Scheme::Redb => "redb",
461            Scheme::Tikv => "tikv",
462            Scheme::Azfile => "azfile",
463            Scheme::Sqlite => "sqlite",
464            Scheme::Mongodb => "mongodb",
465            Scheme::Alluxio => "alluxio",
466            Scheme::Upyun => "upyun",
467            Scheme::YandexDisk => "yandex_disk",
468            Scheme::Pcloud => "pcloud",
469            Scheme::HdfsNative => "hdfs_native",
470            Scheme::Surrealdb => "surrealdb",
471            Scheme::Lakefs => "lakefs",
472            Scheme::NebulaGraph => "nebula_graph",
473            Scheme::Custom(v) => v,
474        }
475    }
476}
477
478impl From<Scheme> for String {
479    fn from(v: Scheme) -> Self {
480        v.into_static().to_string()
481    }
482}