1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
use std::fmt::Display;
use std::fmt::Formatter;
use std::io;
use std::str::FromStr;
use anyhow::anyhow;
use crate::error::other;
use crate::error::BackendError;
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum Scheme {
Azblob,
Fs,
#[cfg(feature = "services-hdfs")]
Hdfs,
#[cfg(feature = "services-http")]
Http,
Memory,
S3,
}
impl Default for Scheme {
fn default() -> Self {
Self::Memory
}
}
impl Display for Scheme {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Scheme::Azblob => write!(f, "azblob"),
Scheme::Fs => write!(f, "fs"),
#[cfg(feature = "services-hdfs")]
Scheme::Hdfs => write!(f, "hdfs"),
#[cfg(feature = "services-http")]
Scheme::Http => write!(f, "http"),
Scheme::Memory => write!(f, "memory"),
Scheme::S3 => write!(f, "s3"),
}
}
}
impl FromStr for Scheme {
type Err = io::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let s = s.to_lowercase();
match s.as_str() {
"azblob" => Ok(Scheme::Azblob),
"fs" => Ok(Scheme::Fs),
#[cfg(feature = "services-hdfs")]
"hdfs" => Ok(Scheme::Hdfs),
"memory" => Ok(Scheme::Memory),
"s3" => Ok(Scheme::S3),
v => Err(other(BackendError::new(
Default::default(),
anyhow!("{} is not supported", v),
))),
}
}
}