1use std::collections::HashSet;
19use std::fmt::Display;
20use std::fmt::Formatter;
21use std::str::FromStr;
22
23use crate::Error;
24
25#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
33#[non_exhaustive]
34pub enum Scheme {
35 AliyunDrive,
37 Atomicserver,
39 Azblob,
41 Azdls,
43 B2,
45 Compfs,
47 Seafile,
49 Upyun,
51 VercelBlob,
53 YandexDisk,
55 Pcloud,
57 Koofr,
59 Cacache,
61 CloudflareKv,
63 Cos,
65 D1,
67 Dashmap,
69 Etcd,
71 Foundationdb,
73 Dbfs,
75 Fs,
77 Ftp,
79 Gcs,
81 Ghac,
83 Hdfs,
85 Http,
87 Huggingface,
89 Alluxio,
91
92 Ipfs,
94 Ipmfs,
96 Icloud,
98 Memcached,
100 Memory,
102 MiniMoka,
104 Moka,
106 Monoiofs,
108 Obs,
110 Onedrive,
112 Gdrive,
114 Dropbox,
116 Oss,
118 Persy,
120 Redis,
122 Postgresql,
124 Mysql,
126 Sqlite,
128 Rocksdb,
130 S3,
132 Sftp,
134 Sled,
136 Swift,
138 VercelArtifacts,
140 Webdav,
142 Webhdfs,
144 Redb,
146 Tikv,
148 Azfile,
150 Mongodb,
152 Gridfs,
154 Github,
156 HdfsNative,
158 Surrealdb,
160 Lakefs,
162 NebulaGraph,
164 Custom(&'static str),
171}
172
173impl Scheme {
174 pub fn into_static(self) -> &'static str {
176 self.into()
177 }
178
179 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 "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}