1#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
5#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
6#[allow(missing_docs)]
7pub enum Scheme {
8 File,
10 Git,
12 Ssh,
14 Http,
16 Https,
18 Ext(String),
22}
23
24impl<'a> From<&'a str> for Scheme {
25 fn from(value: &'a str) -> Self {
26 match value {
27 "ssh" => Scheme::Ssh,
28 "file" => Scheme::File,
29 "git" => Scheme::Git,
30 "http" => Scheme::Http,
31 "https" => Scheme::Https,
32 unknown => Scheme::Ext(unknown.into()),
33 }
34 }
35}
36
37impl Scheme {
38 pub fn as_str(&self) -> &str {
40 use Scheme::*;
41 match self {
42 File => "file",
43 Git => "git",
44 Ssh => "ssh",
45 Http => "http",
46 Https => "https",
47 Ext(name) => name.as_str(),
48 }
49 }
50}
51
52impl std::fmt::Display for Scheme {
53 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
54 f.write_str(self.as_str())
55 }
56}