1#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
5#[cfg_attr(feature = "serde", 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" | "ssh+git" | "git+ssh" => Scheme::Ssh,
29 "file" => Scheme::File,
30 "git" => Scheme::Git,
31 "http" => Scheme::Http,
32 "https" => Scheme::Https,
33 unknown => Scheme::Ext(unknown.into()),
34 }
35 }
36}
37
38impl Scheme {
39 pub fn as_str(&self) -> &str {
41 use Scheme::*;
42 match self {
43 File => "file",
44 Git => "git",
45 Ssh => "ssh",
46 Http => "http",
47 Https => "https",
48 Ext(name) => name.as_str(),
49 }
50 }
51}
52
53impl std::fmt::Display for Scheme {
54 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
55 f.write_str(self.as_str())
56 }
57}