From cb35d1f8db3c38a941462159ce8781174004e78f Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Wed, 18 Oct 2023 12:59:23 +0800 Subject: [PATCH] feat(core): Add enabled for Scheme (#3331) * feat(core): Add enabled for Sceheme Signed-off-by: Xuanwo * Add an example Signed-off-by: Xuanwo --------- Signed-off-by: Xuanwo --- core/src/types/scheme.rs | 105 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/core/src/types/scheme.rs b/core/src/types/scheme.rs index b627d596a5b1..e9b16164055a 100644 --- a/core/src/types/scheme.rs +++ b/core/src/types/scheme.rs @@ -15,6 +15,7 @@ // specific language governing permissions and limitations // under the License. +use std::collections::HashSet; use std::fmt::Display; use std::fmt::Formatter; use std::str::FromStr; @@ -134,6 +135,110 @@ impl Scheme { pub fn into_static(self) -> &'static str { self.into() } + + /// Get all enabled schemes. + /// + /// OpenDAL could be compiled with different features, which will enable different schemes. + /// This function returns all enabled schemes so users can make decisions based on it. + /// + /// # Examples + /// + /// ```rust + /// use opendal::Scheme; + /// + /// let enabled_schemes = Scheme::enabled(); + /// if !enabled_schemes.contains(&Scheme::Memory) { + /// panic!("s3 support is not enabled") + /// } + /// ``` + pub fn enabled() -> HashSet { + HashSet::from([ + #[cfg(feature = "services-atomicserver")] + Scheme::Atomicserver, + #[cfg(feature = "services-azblob")] + Scheme::Azblob, + #[cfg(feature = "services-azdls")] + Scheme::Azdls, + #[cfg(feature = "services-cacache")] + Scheme::Cacache, + #[cfg(feature = "services-cos")] + Scheme::Cos, + #[cfg(feature = "services-dashmap")] + Scheme::Dashmap, + #[cfg(feature = "services-dropbox")] + Scheme::Dropbox, + #[cfg(feature = "services-etcd")] + Scheme::Etcd, + #[cfg(feature = "services-foundationdb")] + Scheme::Foundationdb, + #[cfg(feature = "services-fs")] + Scheme::Fs, + #[cfg(feature = "services-ftp")] + Scheme::Ftp, + #[cfg(feature = "services-gcs")] + Scheme::Gcs, + #[cfg(feature = "services-ghac")] + Scheme::Ghac, + #[cfg(feature = "services-hdfs")] + Scheme::Hdfs, + #[cfg(feature = "services-http")] + Scheme::Http, + #[cfg(feature = "services-ipfs")] + Scheme::Ipfs, + #[cfg(feature = "services-ipmfs")] + Scheme::Ipmfs, + #[cfg(feature = "services-libsql")] + Scheme::Libsql, + #[cfg(feature = "services-memcached")] + Scheme::Memcached, + #[cfg(feature = "services-memory")] + Scheme::Memory, + #[cfg(feature = "services-mini-moka")] + Scheme::MiniMoka, + #[cfg(feature = "services-moka")] + Scheme::Moka, + #[cfg(feature = "services-mysql")] + Scheme::Mysql, + #[cfg(feature = "services-obs")] + Scheme::Obs, + #[cfg(feature = "services-onedrive")] + Scheme::Onedrive, + #[cfg(feature = "services-postgresql")] + Scheme::Postgresql, + #[cfg(feature = "services-gdrive")] + Scheme::Gdrive, + #[cfg(feature = "services-oss")] + Scheme::Oss, + #[cfg(feature = "services-persy")] + Scheme::Persy, + #[cfg(feature = "services-redis")] + Scheme::Redis, + #[cfg(feature = "services-rocksdb")] + Scheme::Rocksdb, + #[cfg(feature = "services-s3")] + Scheme::S3, + #[cfg(feature = "services-sftp")] + Scheme::Sftp, + #[cfg(feature = "services-sled")] + Scheme::Sled, + #[cfg(feature = "services-sqlite")] + Scheme::Sqlite, + #[cfg(feature = "services-supabase")] + Scheme::Supabase, + #[cfg(feature = "services-tikv")] + Scheme::Tikv, + #[cfg(feature = "services-vercel-artifacts")] + Scheme::VercelArtifacts, + #[cfg(feature = "services-wasabi")] + Scheme::Wasabi, + #[cfg(feature = "services-webdav")] + Scheme::Webdav, + #[cfg(feature = "services-webhdfs")] + Scheme::Webhdfs, + #[cfg(feature = "services-redb")] + Scheme::Redb, + ]) + } } impl Default for Scheme {